aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/user.rb12
-rw-r--r--db/migrate/20160803140910_add_code_to_organisations.rb5
-rw-r--r--db/schema.rb5
-rw-r--r--spec/factories/chouette_2_factories.rb1
-rw-r--r--spec/models/user_spec.rb2
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