diff options
| author | Xinhui | 2016-08-03 16:21:22 +0200 | 
|---|---|---|
| committer | Xinhui | 2016-08-03 16:21:22 +0200 | 
| commit | 3dc76115b605dd69c3bc0e24a48860ab874228b8 (patch) | |
| tree | 98eee9253b35bd39493448c815c5e0e324e3f225 | |
| parent | fa7154a9fe684f8b42bfc4afcacaa56bc1fe6d45 (diff) | |
| download | chouette-core-3dc76115b605dd69c3bc0e24a48860ab874228b8.tar.bz2 | |
Add column Code to Organisation
| -rw-r--r-- | app/models/user.rb | 12 | ||||
| -rw-r--r-- | db/migrate/20160803140910_add_code_to_organisations.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 5 | ||||
| -rw-r--r-- | spec/factories/chouette_2_factories.rb | 1 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 2 | 
5 files changed, 19 insertions, 6 deletions
| diff --git a/app/models/user.rb b/app/models/user.rb index a8772ef7b..ffdf632f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -39,12 +39,18 @@ class User < ActiveRecord::Base          self.username = value        end      end -    self.organisation = self.cas_assign_or_create_organisation extra_attributes[:organisation_name] +    self.organisation = self.cas_assign_or_create_organisation( +      { +        code: extra_attributes[:organisation_code],  +        name: extra_attributes[:organisation_name] +      } +    )    end -  def cas_assign_or_create_organisation name -    Organisation.find_or_create_by(name: name) do |organisation| +  def cas_assign_or_create_organisation code:, name: +    Organisation.find_or_create_by(code: code) do |organisation|        organisation.name = name +      organisation.code = code      end    end diff --git a/db/migrate/20160803140910_add_code_to_organisations.rb b/db/migrate/20160803140910_add_code_to_organisations.rb new file mode 100644 index 000000000..ba5d38213 --- /dev/null +++ b/db/migrate/20160803140910_add_code_to_organisations.rb @@ -0,0 +1,5 @@ +class AddCodeToOrganisations < ActiveRecord::Migration +  def change +    add_column :organisations, :code, :string +  end +end diff --git a/db/schema.rb b/db/schema.rb index 354b446f7..85b9abb4f 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: 20160727132836) do +ActiveRecord::Schema.define(version: 20160803140910) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -353,6 +353,7 @@ ActiveRecord::Schema.define(version: 20160727132836) do      t.datetime "created_at"      t.datetime "updated_at"      t.string   "data_format", default: "neptune" +    t.string   "code"    end    create_table "pt_links", force: true do |t| @@ -597,7 +598,7 @@ ActiveRecord::Schema.define(version: 20160727132836) do      t.integer  "invited_by_id"      t.string   "invited_by_type"      t.datetime "invitation_created_at" -    t.string   "username" +    t.string   "username",                            null: false    end    add_index "users", ["email"], :name => "index_users_on_email", :unique => true diff --git a/spec/factories/chouette_2_factories.rb b/spec/factories/chouette_2_factories.rb index 6234f6540..b88b0d773 100644 --- a/spec/factories/chouette_2_factories.rb +++ b/spec/factories/chouette_2_factories.rb @@ -2,6 +2,7 @@ FactoryGirl.define do    factory :organisation do      sequence(:name) { |n| "Organisation #{n}" } +    sequence(:code) { |n| "000#{n}" }    end    factory :referential do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ea1170aa1..9c9efce4b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -32,7 +32,7 @@ describe User, :type => :model do      it 'should not create a new organisation if organisation is already present' do        organisation = create :organisation -      ticket.extra_attributes[:organisation_name] = organisation.name +      ticket.extra_attributes[:organisation_code] = organisation.code        expect{User.authenticate_with_cas_ticket(ticket)}.not_to change{ Organisation.count }      end    end | 
