aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-06-16 12:20:55 +0200
committerXinhui2017-06-16 12:21:15 +0200
commitf862664da731aaa9c7377fc9afc054ba8a033867 (patch)
treeceb5f8a9e9a8e2ceae1161e15081ed25daba787f
parentec35d1614555621a23b6688839ce2b223126e851 (diff)
downloadchouette-core-f862664da731aaa9c7377fc9afc054ba8a033867.tar.bz2
Add auto assign of slug and prefix for referential#create
Refs #3657
-rw-r--r--app/controllers/referentials_controller.rb1
-rw-r--r--app/models/referential.rb10
-rw-r--r--spec/views/referentials/new.html.erb_spec.rb8
3 files changed, 11 insertions, 8 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 6401676fa..aa5b359da 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -74,7 +74,6 @@ class ReferentialsController < BreadcrumbController
alias_method :current_referential, :referential
helper_method :current_referential
-
def resource
@referential ||= current_organisation.find_referential(params[:id])
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 22bfe0d25..286903821 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -179,6 +179,8 @@ class Referential < ActiveRecord::Base
before_validation :assign_line_and_stop_area_referential, :on => :create, if: :workbench, unless: :created_from
before_validation :clone_associations, :on => :create, if: :created_from
+ before_validation :assign_slug, :on => :create
+ before_validation :assign_prefix, :on => :create
before_create :create_schema, unless: :created_from
after_create :clone_schema, if: :created_from
@@ -288,6 +290,14 @@ class Referential < ActiveRecord::Base
Apartment::Tenant.create slug
end
+ def assign_slug
+ self.slug ||= "#{self.name.parameterize.gsub('-', '_')}_#{Time.now.to_i}"
+ end
+
+ def assign_prefix
+ self.prefix = self.organisation.name.parameterize.gsub('-', '_')
+ end
+
def assign_line_and_stop_area_referential
self.line_referential = workbench.line_referential
self.stop_area_referential = workbench.stop_area_referential
diff --git a/spec/views/referentials/new.html.erb_spec.rb b/spec/views/referentials/new.html.erb_spec.rb
index 0673b4578..554e71d29 100644
--- a/spec/views/referentials/new.html.erb_spec.rb
+++ b/spec/views/referentials/new.html.erb_spec.rb
@@ -5,15 +5,9 @@ describe "referentials/new", :type => :view do
before(:each) do
assign(:referential, Referential.new)
end
-
+
it "should have a textfield for name" do
render
expect(rendered).to have_field("referential[name]")
end
-
- it "should have a textfield for slug" do
- render
- expect(rendered).to have_field("referential[slug]")
- end
-
end