Permalink
Browse files

Merge pull request #13 from alphagov/fix-cucumber

Fix Cucumber tests for new sections
  • Loading branch information...
2 parents 6a16707 + 5dc6315 commit 5a256470d914832131bfddcb38cdf73df9be4451 @mnowster mnowster committed Aug 10, 2012
View
@@ -54,7 +54,6 @@ group :test do
gem 'simplecov', '~> 0.6.4'
gem 'simplecov-rcov'
gem 'ci_reporter'
- gem 'test-unit'
gem 'cucumber-rails', require: false
gem 'database_cleaner'
gem 'minitest'
View
@@ -251,7 +251,6 @@ GEM
sqlite3 (>= 1.3.3)
state_machine (1.1.2)
stomp (1.2.5)
- test-unit (2.5.1)
therubyracer (0.9.10)
libv8 (~> 3.3.10)
thor (0.15.4)
@@ -321,7 +320,6 @@ DEPENDENCIES
simplecov-rcov
sqlite3-ruby
stomp
- test-unit
therubyracer (~> 0.9.4)
turn
uglifier
View
@@ -27,20 +27,21 @@ Feature: Editing artefacts
When I try to create a new artefact with the same need
Then I should be redirected to Publisher
-# Scenario: Add a section
-# Given an artefact exists
-# And a section exists
-# When I add the section to the artefact
-# Then I should be redirected to Publisher
-# And the API should say that the artefact has the section
-#
-# Scenario: Remove a section
-# Given an artefact exists
-# And a section exists
-# And the artefact has the section
-# When I remove the section from the artefact
-# Then I should be redirected to Publisher
-# And the API should say that the artefact does not have the section
+ Scenario: Add a section
+ Given an artefact exists
+ And a section exists
+ When I add the section to the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact has the section
+
+ Scenario: Remove a section
+ Given an artefact exists
+ And two sections exist
+ And the artefact has both sections
+ When I remove the second section from the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact has the first section
+ And the API should say that the artefact does not have the second section
Scenario: Editing an item that's draft
Given two artefacts exist
@@ -27,6 +27,14 @@
check_artefact_has_tag_in_api @artefact, @section.tag_id
end
+Then /^the API should say that the artefact has the first section$/ do
+ check_artefact_has_tag_in_api @artefact, @sections[0].tag_id
+end
+
Then /^the API should say that the artefact does not have the section$/ do
check_artefact_does_not_have_tag_in_api @artefact, @section.tag_id
end
+
+Then /^the API should say that the artefact does not have the second section$/ do
+ check_artefact_does_not_have_tag_in_api @artefact, @sections[1].tag_id
+end
@@ -98,6 +98,10 @@
@section = create_section
end
+Given /^two sections exist$/ do
+ @sections = create_sections
+end
+
When /^I add the contact to the artefact$/ do
visit edit_artefact_path(@artefact)
select_contact @contact
@@ -112,6 +116,12 @@
add_section @artefact, @section
end
+Given /^the artefact has both sections$/ do
+ @sections.each do |section|
+ add_section @artefact, section
+ end
+end
+
When /^I remove the contact from the artefact$/ do
visit edit_artefact_path(@artefact)
unselect_contact @contact
@@ -124,9 +134,9 @@
submit_artefact_form
end
-When /^I remove the section from the artefact$/ do
+When /^I remove the second section from the artefact$/ do
visit edit_artefact_path(@artefact)
- unselect_section @section
+ unselect_section @sections[1]
submit_artefact_form
end
View
@@ -29,7 +29,7 @@ def check_artefact_has_name_in_api(artefact, name)
end
def check_artefact_has_related_artefact_in_api(artefact, related_artefact)
- assert_include related_artefact_ids_from_api(artefact), related_artefact.id.to_s
+ assert_includes related_artefact_ids_from_api(artefact), related_artefact.id.to_s
end
def check_artefact_has_related_artefacts_in_api(artefact, related_artefacts)
@@ -39,7 +39,7 @@ def check_artefact_has_related_artefacts_in_api(artefact, related_artefacts)
end
def check_artefact_does_not_have_related_artefact_in_api(artefact, unrelated_artefact)
- assert_not_include related_artefact_ids_from_api(artefact), unrelated_artefact.id.to_s
+ refute_includes related_artefact_ids_from_api(artefact), unrelated_artefact.id.to_s
end
def check_artefact_has_contact_in_api(artefact, contact)
@@ -51,9 +51,9 @@ def check_artefact_does_not_have_contact_in_api(artefact, contact)
end
def check_artefact_has_tag_in_api(artefact, tag_id)
- assert_include tag_ids_from_api(artefact), tag_id
+ assert_includes tag_ids_from_api(artefact), tag_id
end
def check_artefact_does_not_have_tag_in_api(artefact, tag_id)
- assert_not_include tag_ids_from_api(artefact), tag_id
+ refute_includes tag_ids_from_api(artefact), tag_id
end
@@ -1,16 +1,37 @@
def create_section
- TagRepository.put :tag_id => 'crime', :tag_type => 'section', :title => 'Crime'
- return TagRepository.load 'crime'
+ TagRepository.put(
+ tag_id: "crime",
+ tag_type: "section",
+ title: "Crime"
+ )
+ return TagRepository.load "crime"
+end
+
+def create_sections
+ create_section
+ TagRepository.put(
+ tag_id: "crime/batman",
+ tag_type: "section",
+ title: "Batman"
+ )
+ return ["crime", "crime/batman"].map { |tag_id| TagRepository.load tag_id }
end
def select_section(section)
- select section.title, :from => 'Sections'
+ select section.title, :from => "artefact[sections][]"
end
def unselect_section(section)
- unselect section.title, :from => 'Sections'
+ tag_id = section.tag_id
+ within(:xpath, "//option[@value='#{tag_id}'][@selected='selected']/../..") do
+ # Can't rely on the Remove button here, as JavaScript may not have loaded
+ # and the buttons aren't full of progressive enhancement goodness
+ select "Select a section", from: "artefact[sections][]"
+ end
end
def add_section(artefact, section)
- artefact.sections += [section.tag_id]
+ # Ugh, inconsistent section getting and setting
+ artefact.sections = (artefact.sections + [section]).map(&:tag_id)
+ artefact.save!
end
View
@@ -2,4 +2,4 @@
export RAILS_ENV=test
bundle install --path "${HOME}/bundles/${JOB_NAME}" --deployment
bundle exec rake db:drop db:create db:schema:load
-bundle exec rake test
+bundle exec rake
View
@@ -55,6 +55,4 @@ def login_as(user)
def teardown
WebMock.reset!
end
-
- alias_method :refute, :assert_false
end

0 comments on commit 5a25647

Please sign in to comment.