aboutsummaryrefslogtreecommitdiffstats
path: root/spec/views
diff options
context:
space:
mode:
authorAlban Peignier2017-12-21 21:27:51 +0100
committerGitHub2017-12-21 21:27:51 +0100
commit01b2d2b785d99c9b031269fc741b70ee9c248f16 (patch)
tree5660c31a263a7a71d4bdb4bb68159b9479ca8a00 /spec/views
parent8cd9b9ee5fc127b2f39a9c89c71327ab8d5e9cec (diff)
parent4be4d378d15ad24c8ca0cd43befb25d94cd093de (diff)
downloadchouette-core-01b2d2b785d99c9b031269fc741b70ee9c248f16.tar.bz2
Merge pull request #165 from af83/5340-deactivate-lines
Deactivate lines instead of destroying them. Refs #5340
Diffstat (limited to 'spec/views')
-rw-r--r--spec/views/lines/index.html.erb_spec.rb27
-rw-r--r--spec/views/lines/index.html.slim_spec.rb71
2 files changed, 71 insertions, 27 deletions
diff --git a/spec/views/lines/index.html.erb_spec.rb b/spec/views/lines/index.html.erb_spec.rb
deleted file mode 100644
index dbc3cbdb7..000000000
--- a/spec/views/lines/index.html.erb_spec.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require 'spec_helper'
-
-describe "/lines/index", :type => :view do
-
- let!(:line_referential) { assign :line_referential, create(:line_referential) }
- let!(:network) { create :network }
- let!(:company) { create :company }
- let!(:lines) { assign :lines, Array.new(2) { create(:line, line_referential: line_referential, network: network, company: company) }.paginate }
- let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
-
- before :each do
- allow(view).to receive(:link_with_search).and_return("#")
- end
-
- # it "should render a show link for each group" do
- # render
- # lines.each do |line|
- # expect(rendered).to have_selector(".line a[href='#{view.line_referential_line_path(line_referential, line)}']", :text => line.name)
- # end
- # end
- #
- # it "should render a link to create a new group" do
- # render
- # expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_line_path(line_referential)}']")
- # end
-
-end
diff --git a/spec/views/lines/index.html.slim_spec.rb b/spec/views/lines/index.html.slim_spec.rb
new file mode 100644
index 000000000..498784912
--- /dev/null
+++ b/spec/views/lines/index.html.slim_spec.rb
@@ -0,0 +1,71 @@
+require 'spec_helper'
+
+describe "/lines/index", :type => :view do
+ let(:deactivated_line){ nil }
+ let(:line_referential) { assign :line_referential, create(:line_referential) }
+ let(:current_organisation) { current_user.organisation }
+ let(:context) {
+ {
+ current_organisation: current_organisation,
+ line_referential: line_referential
+ }
+ }
+ let(:lines) do
+ assign :lines, build_paginated_collection(:line, LineDecorator, line_referential: line_referential, context: context)
+ end
+ let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
+
+ before :each do
+ deactivated_line
+ allow(view).to receive(:collection).and_return(lines)
+ allow(view).to receive(:current_referential).and_return(line_referential)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ render
+ end
+
+ common_items = ->{
+ it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) }
+ it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) }
+ it { should have_link_for_each_item(lines, "company", -> (line){ view.line_referential_company_path(line_referential, line.company) }) }
+ }
+
+ common_items.call()
+ it { should have_the_right_number_of_links(lines, 3) }
+
+ with_permission "lines.change_status" do
+ common_items.call()
+ it { should have_link_for_each_item(lines, "deactivate", -> (line){ view.deactivate_line_referential_line_path(line_referential, line) }) }
+ it { should have_the_right_number_of_links(lines, 4) }
+ end
+
+ with_permission "lines.destroy" do
+ common_items.call()
+ it {
+ should have_link_for_each_item(lines, "destroy", {
+ href: ->(line){ view.line_referential_line_path(line_referential, line)},
+ method: :delete
+ })
+ }
+ it { should have_the_right_number_of_links(lines, 4) }
+ end
+
+ context "with a deactivated item" do
+ with_permission "lines.change_status" do
+ let(:deactivated_line){ create :line, deactivated: true }
+
+ common_items.call()
+ it "should display an activate link for the deactivated one" do
+ lines.each do |line|
+ if line == deactivated_line
+ href = view.activate_line_referential_line_path(line_referential, line)
+ else
+ href = view.deactivate_line_referential_line_path(line_referential, line)
+ end
+ selector = "tr.#{TableBuilderHelper.item_row_class_name(lines)}-#{line.id} .actions a[href='#{href}']"
+ expect(rendered).to have_selector(selector, count: 1)
+ end
+ end
+ it { should have_the_right_number_of_links(lines, 4) }
+ end
+ end
+end