diff options
| author | Marc Florisson | 2015-02-20 22:16:13 +0100 |
|---|---|---|
| committer | Marc Florisson | 2015-02-20 22:16:13 +0100 |
| commit | 9730870608fc78a94a8367d8ab508ee23a9d20b6 (patch) | |
| tree | c4526d668b496da055eab0ce908f87f6d9e8c755 /spec | |
| parent | 254dbb9ed3d22d3bd1427d3a771517abffbebe23 (diff) | |
| download | chouette-core-9730870608fc78a94a8367d8ab508ee23a9d20b6.tar.bz2 | |
refactor rule parameter set, move to organisation's level
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories.rb | 6 | ||||
| -rw-r--r-- | spec/models/line_spec.rb | 20 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/referential_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/rule_parameter_set_spec.rb | 4 | ||||
| -rw-r--r-- | spec/support/referential.rb | 14 | ||||
| -rw-r--r-- | spec/views/rule_parameter_sets/index.html.erb_spec.rb | 13 | ||||
| -rw-r--r-- | spec/views/rule_parameter_sets/new.html.erb_spec.rb | 4 |
8 files changed, 41 insertions, 30 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index 2599645d3..f0858e643 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,9 +15,9 @@ FactoryGirl.define do factory :rule_parameter_set do |f| f.sequence(:name) { |n| "Test #{n}" } - f.association :referential + f.association :organisation f.after_create do |rsp| - rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.referential).parameters + rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters end end @@ -70,6 +70,6 @@ FactoryGirl.define do f.referential { Referential.find_by_slug("first") } end - factory :time_table_combination + factory :time_table_combination end diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb index 0b7fcac1c..143d26075 100644 --- a/spec/models/line_spec.rb +++ b/spec/models/line_spec.rb @@ -9,13 +9,13 @@ describe "sdflkjskdjf" do end describe "validation objectid unique constraint" do - let(:organisation){subject.referential.organisation} + let(:referential){subject.referential} let(:objectid_a){ "A:Line:1234" } let(:objectid_b){ "B:Line:1234" } let!(:second_line){ Factory( :line, :objectid => objectid_a, :registration_number => "123456") } - context "when organisation works with HUB" do + context "when referential works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => true + referential.update_attributes :hub_restrictions => true subject.update_attributes :objectid => objectid_a end it "should have objectid with a third part shorter than 14 char" do @@ -23,9 +23,9 @@ describe "sdflkjskdjf" do subject.should_not be_valid end end - context "when organisation doesn't works with HUB" do + context "when referential doesn't works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => false + referential.update_attributes :hub_restrictions => false end it "should have objectid with a third part shorter than 14 char" do subject.update_attributes :objectid => objectid_b @@ -34,19 +34,19 @@ describe "sdflkjskdjf" do end end describe "validation objectid size" do - let(:organisation){subject.referential.organisation} - context "when organisation works with HUB" do + let(:referential){subject.referential} + context "when referential works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => true + referential.update_attributes :hub_restrictions => true end it "should have objectid with a third part shorter than 14 char" do set_large_object_id( subject) subject.should_not be_valid end end - context "when organisation doesn't works with HUB" do + context "when referential doesn't works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => false + referential.update_attributes :hub_restrictions => false end it "should have objectid with a third part shorter than 14 char" do set_large_object_id( subject) diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 6baf13c46..ffac3374b 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -4,4 +4,9 @@ describe Organisation do it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:name) } + + it "create a rule_parameter_set" do + organisation = Factory.create(:organisation) + organisation.rule_parameter_sets.size.should == 1 + end end diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 5ea88ad20..84bf0a131 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -6,10 +6,5 @@ describe Referential do it { should validate_presence_of(:slug) } it { should validate_presence_of(:prefix) } it { should validate_presence_of(:time_zone) } - - it "create a rule_parameter_set" do - referential = Factory.create(:referential) - referential.rule_parameter_sets.size.should == 1 - end end diff --git a/spec/models/rule_parameter_set_spec.rb b/spec/models/rule_parameter_set_spec.rb index 3e872598f..bf33c0c13 100644 --- a/spec/models/rule_parameter_set_spec.rb +++ b/spec/models/rule_parameter_set_spec.rb @@ -37,9 +37,9 @@ describe RuleParameterSet do it { should allow_mass_assignment_of attribute.to_sym} end - describe "#referential" do + describe "#organisation" do #it { should validate_presence_of(:referential) } - it { should allow_mass_assignment_of :referential_id } + it { should allow_mass_assignment_of :organisation_id } end describe "#name" do diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 28f3799ec..e581e9a3a 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -1,13 +1,17 @@ module ReferentialHelper def first_referential - Organisation.find_by_name("first").referentials.find_by_slug("first") + first_organisation.referentials.find_by_slug("first") + end + def first_organisation + Organisation.find_by_name("first") end def self.included(base) base.class_eval do extend ClassMethods alias_method :referential, :first_referential + alias_method :organisation, :first_organisation end end @@ -18,6 +22,12 @@ module ReferentialHelper assign :referential, referential end end + def assign_organisation + before(:each) do + assign :organisation, referential.organisation + end + end + end @@ -29,7 +39,7 @@ RSpec.configure do |config| config.before(:suite) do organisation = Organisation.find_or_create_by_name :name => "first" organisation.referentials.find_by_slug("first" ) || - Referential.create(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation) + Referential.create(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation) # FIXME in Rails 3.2 : # Referential.where(:slug => 'first').first_or_create(FactoryGirl.attributes_for(:referential)) end diff --git a/spec/views/rule_parameter_sets/index.html.erb_spec.rb b/spec/views/rule_parameter_sets/index.html.erb_spec.rb index 0f50ea387..72f20a65e 100644 --- a/spec/views/rule_parameter_sets/index.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/index.html.erb_spec.rb @@ -1,21 +1,22 @@ require 'spec_helper' -describe "/rule_parameter_sets/index" do +describe "/organisations/show" do - assign_referential - let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ Factory(:rule_parameter_set), - Factory(:rule_parameter_set)] } + assign_organisation + + let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ Factory(:rule_parameter_set, :organisation => organisation), + Factory(:rule_parameter_set, :organisation => organisation)] } it "should render a show link for each rule_parameter_set" do render rule_parameter_sets.each do |rule_parameter_set| - rendered.should have_selector(".rule_parameter_set a[href='#{view.referential_rule_parameter_set_path(referential, rule_parameter_set)}']", :text => rule_parameter_set.name) + rendered.should have_selector(".rule_parameter_sets a[href='#{view.organisation_rule_parameter_set_path( rule_parameter_set)}']", :text => rule_parameter_set.name) end end it "should render a link to create a new rule_parameter_set" do render - view.content_for(:sidebar).should have_selector(".actions a[href='#{new_referential_rule_parameter_set_path(referential)}']") + view.content_for(:sidebar).should have_selector(".actions a[href='#{new_organisation_rule_parameter_set_path}']") end end diff --git a/spec/views/rule_parameter_sets/new.html.erb_spec.rb b/spec/views/rule_parameter_sets/new.html.erb_spec.rb index 4670ecceb..c78d04c7c 100644 --- a/spec/views/rule_parameter_sets/new.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/new.html.erb_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe "/rule_parameter_sets/new" do - assign_referential - let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :referential => referential) } + assign_organisation + let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :organisation => organisation) } describe "form" do |
