Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request #13 from alphagov/fix-cucumber
Browse files Browse the repository at this point in the history
Fix Cucumber tests for new sections
  • Loading branch information
mnowster committed Aug 10, 2012
2 parents 6a16707 + 5dc6315 commit 5a25647
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 31 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -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)
Expand Down Expand Up @@ -321,7 +320,6 @@ DEPENDENCIES
simplecov-rcov
sqlite3-ruby
stomp
test-unit
therubyracer (~> 0.9.4)
turn
uglifier
Expand Down
29 changes: 15 additions & 14 deletions features/editing.feature
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/api_steps.rb
Expand Up @@ -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
14 changes: 12 additions & 2 deletions features/step_definitions/artefact_steps.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions features/support/api.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
31 changes: 26 additions & 5 deletions features/support/sections.rb
@@ -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
2 changes: 1 addition & 1 deletion jenkins.sh
Expand Up @@ -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
2 changes: 0 additions & 2 deletions test/test_helper.rb
Expand Up @@ -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.