diff --git a/app/controllers/organizations/registrations_controller.rb b/app/controllers/organizations/registrations_controller.rb index 0341ef4ed..c0f69da33 100644 --- a/app/controllers/organizations/registrations_controller.rb +++ b/app/controllers/organizations/registrations_controller.rb @@ -29,7 +29,7 @@ class Organizations::RegistrationsController < Devise::RegistrationsController private def sign_up_params - params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :captcha, :captcha_key, :terms_of_service, organization_attributes: [:name]) + params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :captcha, :captcha_key, :terms_of_service, organization_attributes: [:name, :responsible_name]) end end diff --git a/app/models/organization.rb b/app/models/organization.rb index 0797849e7..069afc27f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -3,7 +3,9 @@ class Organization < ActiveRecord::Base validates :name, presence: true validates :name, uniqueness: true - validate :validate_name_length + validate :validate_name_length + validates :responsible_name, presence: true + validate :validate_responsible_name_length delegate :email, :phone_number, to: :user @@ -37,6 +39,10 @@ class Organization < ActiveRecord::Base @@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit || 60 end + def self.responsible_name_max_length + @@responsible_name_max_length ||= self.columns.find { |c| c.name == 'responsible_name' }.limit || 60 + end + private def validate_name_length @@ -46,4 +52,11 @@ class Organization < ActiveRecord::Base validator.validate(self) end + def validate_responsible_name_length + validator = ActiveModel::Validations::LengthValidator.new( + attributes: :responsible_name, + maximum: Organization.responsible_name_max_length) + validator.validate(self) + end + end diff --git a/app/views/organizations/registrations/new.html.erb b/app/views/organizations/registrations/new.html.erb index 1b95a2d5d..b9bc32f4a 100644 --- a/app/views/organizations/registrations/new.html.erb +++ b/app/views/organizations/registrations/new.html.erb @@ -7,9 +7,12 @@ <%= f.fields_for :organization do |fo| %> <%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %> + <%= fo.label t("devise_views.organizations.registrations.new.responsible_name_label") %> + <%= t("devise_views.organizations.registrations.new.responsible_name_note") %> + <%= fo.text_field :responsible_name, maxlength: Organization.responsible_name_max_length, label: false %> <% end %> - <%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %> + <%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %> <%= f.text_field :phone_number, placeholder: t("devise_views.organizations.registrations.new.phone_number_label") %> diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 94b1fa0c9..7967520e9 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -25,3 +25,4 @@ en: official_level: Official level organization: name: Organization name + responsible_name: Person in charge diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index f566026de..695c72df6 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -25,3 +25,4 @@ es: official_level: Nivel del cargo organization: name: Nombre de organización + responsible_name: Persona responsable del colectivo diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 9562f63f8..f4058837f 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -74,6 +74,8 @@ en: new: title: "Sign up as organization / collective" organization_name_label: "Organization name" + responsible_name_label: "Name and surname of the person in charge" + responsible_name_note: "The responsible representative of the organization" email_label: "Email" password_label: "Password" phone_number_label: "Phone number" diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index 9fa3a5adc..814d4e535 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -74,6 +74,8 @@ es: new: title: "Registrarse como organización / colectivo" organization_name_label: "Nombre de la organización" + responsible_name_label: "Nombre y apellidos de la persona responsable del colectivo" + responsible_name_note: "Será la persona representante de la asociación/colectivo en cuyo nombre se presenten las propuestas" email_label: "Email" password_label: "Contraseña" phone_number_label: "Teléfono" diff --git a/db/migrate/20150912145218_add_responsible_name_to_organizations.rb b/db/migrate/20150912145218_add_responsible_name_to_organizations.rb new file mode 100644 index 000000000..ffffd31ce --- /dev/null +++ b/db/migrate/20150912145218_add_responsible_name_to_organizations.rb @@ -0,0 +1,5 @@ +class AddResponsibleNameToOrganizations < ActiveRecord::Migration + def change + add_column :organizations, :responsible_name, :string, limit: 60 + end +end diff --git a/db/schema.rb b/db/schema.rb index fde03fe30..40408573d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150910152734) do +ActiveRecord::Schema.define(version: 20150912145218) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -165,7 +165,7 @@ ActiveRecord::Schema.define(version: 20150910152734) do create_table "locks", force: :cascade do |t| t.integer "user_id" t.integer "tries", default: 0 - t.datetime "locked_until", default: '2015-09-10 13:46:11', null: false + t.datetime "locked_until", default: '2015-09-11 17:24:30', null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -180,13 +180,32 @@ ActiveRecord::Schema.define(version: 20150910152734) do create_table "organizations", force: :cascade do |t| t.integer "user_id" - t.string "name", limit: 60 + t.string "name", limit: 60 t.datetime "verified_at" t.datetime "rejected_at" + t.string "responsible_name", limit: 60 end add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree + create_table "proposals", force: :cascade do |t| + t.string "title", limit: 80 + t.text "description" + t.string "question" + t.string "external_url" + t.integer "author_id" + t.datetime "hidden_at" + t.integer "flags_count", default: 0 + t.datetime "ignored_flag_at" + t.integer "cached_votes_up", default: 0 + t.integer "comments_count", default: 0 + t.datetime "confirmed_hide_at" + t.integer "hot_score", limit: 8, default: 0 + t.integer "confidence_score", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "settings", force: :cascade do |t| t.string "key" t.string "value" @@ -246,7 +265,7 @@ ActiveRecord::Schema.define(version: 20150910152734) do t.integer "official_level", default: 0 t.datetime "hidden_at" t.string "sms_confirmation_code" - t.string "username", limit: 60 + t.string "username", limit: 60 t.string "document_number" t.string "document_type" t.datetime "residence_verified_at" diff --git a/spec/factories.rb b/spec/factories.rb index ff3f60540..8513d4d16 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -149,6 +149,7 @@ FactoryGirl.define do factory :organization do user + responsible_name "Johnny Utah" sequence(:name) { |n| "org#{n}" } trait :verified do diff --git a/spec/features/organizations_spec.rb b/spec/features/organizations_spec.rb index 15cd4b41b..a42e78dad 100644 --- a/spec/features/organizations_spec.rb +++ b/spec/features/organizations_spec.rb @@ -9,6 +9,7 @@ feature 'Organizations' do visit new_organization_registration_path fill_in 'user_organization_attributes_name', with: 'Greenpeace' + fill_in 'user_organization_attributes_responsible_name', with: 'Dorothy Stowe' fill_in 'user_email', with: 'green@peace.com' fill_in 'user_password', with: 'greenpeace' fill_in 'user_password_confirmation', with: 'greenpeace' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e8e710dd0..756810395 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -161,11 +161,12 @@ describe User do end describe "organization_attributes" do - before(:each) { subject.organization_attributes = {name: 'org'} } + before(:each) { subject.organization_attributes = {name: 'org', responsible_name: 'julia'} } it "triggers the creation of an associated organization" do expect(subject.organization).to be expect(subject.organization.name).to eq('org') + expect(subject.organization.responsible_name).to eq('julia') end it "deactivates the validation of username, and activates the validation of organization" do