aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/referentials_controller_spec.rb52
-rw-r--r--spec/decorators/referential_decorator_spec.rb15
-rw-r--r--spec/features/referentials_spec.rb12
-rw-r--r--spec/features/workbenches/workbenches_permissions_spec.rb2
-rw-r--r--spec/features/workbenches/workbenches_show_spec.rb4
-rw-r--r--spec/helpers/table_builder_helper_spec.rb22
-rw-r--r--spec/support/decorator_helpers.rb1
-rw-r--r--spec/views/referentials/show.html.erb_spec.rb57
8 files changed, 92 insertions, 73 deletions
diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb
index f97480600..5e0b1e505 100644
--- a/spec/controllers/referentials_controller_spec.rb
+++ b/spec/controllers/referentials_controller_spec.rb
@@ -15,8 +15,7 @@ describe ReferentialsController, :type => :controller do
end
context "user's organisation doesn't match referential's organisation" do
- pending "hotfix opens all unknow actions need to close the uneeded later" do
- #it 'raises a ActiveRecord::RecordNotFound' do
+ it 'raises a ActiveRecord::RecordNotFound' do
expect { put :archive, id: other_referential.id }.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -26,7 +25,7 @@ describe ReferentialsController, :type => :controller do
it 'gets compliance control set for current organisation' do
compliance_control_set = create(:compliance_control_set, organisation: @user.organisation)
create(:compliance_control_set)
- get :select_compliance_control_set, referential_id: referential.id
+ get :select_compliance_control_set, id: referential.id
expect(assigns[:compliance_control_sets]).to eq([compliance_control_set])
end
end
@@ -43,16 +42,51 @@ describe ReferentialsController, :type => :controller do
end
end
+ describe "GET #new" do
+ context "when duplicating" do
+ let(:workbench){ create :workbench}
+ let(:request){
+ get :new,
+ workbench_id: workbench.id,
+ from: referential.id
+ }
+
+ it "duplicates the given referential" do
+ request
+ new_referential = assigns(:referential)
+ expect(new_referential.line_referential).to eq referential.line_referential
+ expect(new_referential.stop_area_referential).to eq referential.stop_area_referential
+ expect(new_referential.objectid_format).to eq referential.objectid_format
+ expect(new_referential.prefix).to eq referential.prefix
+ expect(new_referential.slug).to eq "#{referential.slug}_clone"
+ expect(new_referential.workbench).to eq workbench
+ end
+ end
+ end
+
describe "POST #create" do
+ let(:workbench){ create :workbench}
context "when duplicating" do
- it "displays a flash message", pending: 'requires more params to create a valid Referential' do
+ let(:request){
post :create,
- from: referential.id,
- current_workbench_id: referential.workbench_id,
- referential: {
- name: 'Duplicated'
- }
+ workbench_id: workbench.id,
+ referential: {
+ name: 'Duplicated',
+ created_from_id: referential.id,
+ stop_area_referential: referential.stop_area_referential,
+ line_referential: referential.line_referential,
+ objectid_format: referential.objectid_format,
+ workbench_id: referential.workbench_id
+ }
+ }
+
+ it "creates the new referential" do
+ expect{request}.to change{Referential.count}.by 1
+ expect(Referential.last.name).to eq "Duplicated"
+ end
+ it "displays a flash message" do
+ request
expect(controller).to set_flash[:notice].to(
I18n.t('notice.referentials.duplicate')
)
diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb
index efc438132..1224aaf75 100644
--- a/spec/decorators/referential_decorator_spec.rb
+++ b/spec/decorators/referential_decorator_spec.rb
@@ -1,7 +1,8 @@
RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
include Support::DecoratorHelpers
- let( :object ){ build_stubbed :referential }
+ let( :workbench ){ build_stubbed :workbench }
+ let( :object ){ build_stubbed :referential, workbench: workbench }
let( :referential ){ object }
let( :user ){ build_stubbed :user }
@@ -35,7 +36,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs.to eq([
[object],
referential_time_tables_path(object),
- new_referential_path(from: object)
+ new_workbench_referential_path(referential.workbench, from: object.id)
])
end
end
@@ -50,8 +51,8 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
[object],
[:edit, object],
referential_time_tables_path(object),
- new_referential_path(from: object),
- referential_select_compliance_control_set_path(object),
+ new_workbench_referential_path(referential.workbench, from: object.id),
+ select_compliance_control_set_referential_path(object),
archive_referential_path(object),
referential_path(object)
])
@@ -65,8 +66,8 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs(action).to eq([
[:edit, object],
referential_time_tables_path(object),
- new_referential_path(from: object),
- referential_select_compliance_control_set_path(object),
+ new_workbench_referential_path(referential.workbench, from: object.id),
+ select_compliance_control_set_referential_path(object),
archive_referential_path(object),
"#",
referential_path(object)
@@ -91,7 +92,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs.to eq([
[object],
referential_time_tables_path(object),
- new_referential_path(from: object)
+ new_workbench_referential_path(referential.workbench, from: object.id)
])
end
end
diff --git a/spec/features/referentials_spec.rb b/spec/features/referentials_spec.rb
index 9af0ed32e..d4890fda4 100644
--- a/spec/features/referentials_spec.rb
+++ b/spec/features/referentials_spec.rb
@@ -55,7 +55,7 @@ describe "Referentials", :type => :feature do
context 'user has the permission to create referentials' do
it 'shows the clone link for referetnial' do
- expect(page).to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
+ expect(page).to have_link(I18n.t('actions.clone'), href: new_workbench_referential_path(referential.workbench, from: referential.id))
end
end
@@ -63,7 +63,7 @@ describe "Referentials", :type => :feature do
it 'does not show the clone link for referetnial' do
@user.update_attribute(:permissions, [])
visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
+ expect(page).not_to have_link(I18n.t('actions.clone'), href: new_workbench_referential_path(referential.workbench, from: referential.id))
end
end
@@ -108,8 +108,9 @@ describe "Referentials", :type => :feature do
end
describe "create" do
+ let(:workbench){ @user.organisation.workbenches.last }
it "should" do
- visit new_referential_path
+ visit new_workbench_referential_path(workbench)
fill_in "Nom", :with => "Test"
click_button "Valider"
@@ -132,7 +133,7 @@ describe "Referentials", :type => :feature do
context "when user is from the same organisation" do
xit "should" do
- visit new_referential_path(from: referential.id, current_workbench_id: @user.organisation.workbenches.first.id)
+ visit new_workbench_referential_path(referential.workbench, from: referential.id, current_workbench_id: @user.organisation.workbenches.first.id)
select "2018", :from => "referential_metadatas_attributes_0_periods_attributes_0_begin_1i"
@@ -187,7 +188,8 @@ describe "Referentials", :type => :feature do
end
describe "destroy" do
- let(:referential) { create(:referential, :organisation => @user.organisation) }
+ let(:workbench){ @user.organisation.workbenches.last }
+ let(:referential) { create(:referential, :organisation => @user.organisation, workbench: workbench) }
it "should remove referential" do
visit referential_path(referential)
diff --git a/spec/features/workbenches/workbenches_permissions_spec.rb b/spec/features/workbenches/workbenches_permissions_spec.rb
index d58293538..1c073a4c5 100644
--- a/spec/features/workbenches/workbenches_permissions_spec.rb
+++ b/spec/features/workbenches/workbenches_permissions_spec.rb
@@ -22,7 +22,7 @@ describe 'Workbenches', type: :feature do
let( :permission ){ true }
it 'shows the corresponding button' do
- expected_href = new_referential_path(workbench_id: workbench)
+ expected_href = new_workbench_referential_path(workbench)
expect( page ).to have_link('Créer', href: expected_href)
end
end
diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb
index 7be813b94..405fdce82 100644
--- a/spec/features/workbenches/workbenches_show_spec.rb
+++ b/spec/features/workbenches/workbenches_show_spec.rb
@@ -232,7 +232,7 @@ RSpec.describe 'Workbenches', type: :feature do
context 'user has the permission to create referentials' do
it 'shows the link for a new referetnial' do
- expect(page).to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ expect(page).to have_link(I18n.t('actions.add'), href: new_workbench_referential_path(workbench))
end
end
@@ -240,7 +240,7 @@ RSpec.describe 'Workbenches', type: :feature do
it 'does not show the clone link for referential' do
@user.update_attribute(:permissions, [])
visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ expect(page).not_to have_link(I18n.t('actions.add'), href: new_workbench_referential_path(workbench))
end
end
end
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 5bddbb16f..478875118 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -15,8 +15,9 @@ describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- referential = build_stubbed(:workbench_referential)
+ referential = create(:workbench_referential)
workbench = referential.workbench
+ referential.organisation.workbenches << workbench
user_context = UserContext.new(
build_stubbed(
@@ -30,7 +31,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
referentials = [referential]
@@ -90,7 +92,7 @@ describe TableBuilderHelper, type: :helper do
</ul>
<ul class="other">
<li class=""><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li>
- <li class=""><a href="/referentials/new?from=#{referential.id}">Dupliquer</a></li>
+ <li class=""><a href="/workbenches/#{workbench.id}/referentials/new?from=#{referential.id}">Dupliquer</a></li>
<li class=""><a href="/referentials/#{referential.id}/select_compliance_control_set">Valider</a></li>
<li class=""><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li>
</ul>
@@ -193,7 +195,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
allow(helper).to receive(:current_referential)
.and_return(referential)
@@ -307,7 +310,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
allow(helper).to receive(:current_referential)
.and_return(referential)
@@ -398,8 +402,8 @@ describe TableBuilderHelper, type: :helper do
end
context "on a single row" do
- let(:referential){ build_stubbed :referential }
- let(:other_referential){ build_stubbed :referential }
+ let(:referential){ build_stubbed :workbench_referential }
+ let(:other_referential){ build_stubbed :workbench_referential }
let(:user_context){
UserContext.new(
build_stubbed(
@@ -432,7 +436,9 @@ describe TableBuilderHelper, type: :helper do
let(:items){ [item, other_item] }
before(:each){
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
+ allow(helper).to receive(:mutual_workbench).and_return(referential.workbench)
}
context "with all rows non-selectable" do
diff --git a/spec/support/decorator_helpers.rb b/spec/support/decorator_helpers.rb
index b2c41e842..544604f61 100644
--- a/spec/support/decorator_helpers.rb
+++ b/spec/support/decorator_helpers.rb
@@ -8,6 +8,7 @@ module Support
let( :features ){ [] }
let( :filtered_action_links){}
before do
+ allow(subject.h).to receive(:duplicate_workbench_referential_path).and_return new_workbench_referential_path(referential.workbench, from: referential.id)
allow_any_instance_of(Draper::HelperProxy).to receive(:policy).and_return policy
allow_any_instance_of(AF83::Decorator::Link).to receive(:check_feature){|f|
features.include?(f)
diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb
index ea3bc1fe1..a7f37d180 100644
--- a/spec/views/referentials/show.html.erb_spec.rb
+++ b/spec/views/referentials/show.html.erb_spec.rb
@@ -1,73 +1,48 @@
require 'spec_helper'
describe "referentials/show", type: :view do
+
let!(:referential) do
- referential = create(:referential, organisation: organisation)
+ referential = create(:workbench_referential)
assign :referential, referential.decorate(context: {
current_organisation: referential.organisation
})
end
+ let(:organisation){ referential.try(:organisation) }
let(:permissions){ [] }
let(:current_organisation) { organisation }
- let(:current_offer_workbench) { create :workbench, organisation: organisation}
- let(:current_workgroup) { current_offer_workbench.workgroup }
let(:readonly){ false }
before :each do
assign :reflines, []
- allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench)
allow(view).to receive(:current_organisation).and_return(current_organisation)
- allow(view).to receive(:current_workgroup).and_return(current_workgroup)
allow(view).to receive(:current_user).and_return(current_user)
-
allow(view).to receive(:resource).and_return(referential)
allow(view).to receive(:has_feature?).and_return(true)
allow(view).to receive(:user_signed_in?).and_return true
+ allow(view).to receive(:mutual_workbench).and_return referential.workbench
controller.request.path_parameters[:id] = referential.id
allow(view).to receive(:params).and_return({action: :show})
allow(referential).to receive(:referential_read_only?){ readonly }
+ render template: "referentials/show", layout: "layouts/application"
end
- describe "action links" do
- set_invariant "referential.object.full_name", "referential_full_name"
- set_invariant "referential.object.updated_at", "01/01/2000 00:00".to_time
- set_invariant "referential.object.id", "99"
-
- before(:each){
- render template: "referentials/show", layout: "layouts/application"
- }
- context "with a readonly referential" do
- let(:readonly){ true }
- it { should match_actions_links_snapshot "referentials/show_readonly" }
-
- %w(create destroy update).each do |p|
- with_permission "referentials.#{p}" do
- it { should match_actions_links_snapshot "referentials/show_readonly_#{p}" }
- end
- end
- end
-
- context "with a non-readonly referential" do
- it { should match_actions_links_snapshot "referentials/show" }
+ it "should not present edit button" do
+ expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
+ end
- %w(create destroy update).each do |p|
- with_permission "referentials.#{p}" do
- it { should match_actions_links_snapshot "referentials/show_#{p}" }
- end
- end
+ with_permission "referentials.update" do
+ it "should present edit button" do
+ expect(rendered).to have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
end
- %w(purchase_windows referential_vehicle_journeys).each do |f|
- with_feature f do
- it { should match_actions_links_snapshot "referentials/show_#{f}" }
-
- %w(create update destroy).each do |p|
- with_permission "referentials.#{p}" do
- it { should match_actions_links_snapshot "referentials/show_#{f}_#{p}" }
- end
- end
+ context "with a readonly referential" do
+ let(:readonly){ true }
+ it "should not present edit button" do
+ expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
end
end
end
+
end