Created
August 24, 2011 11:29
-
-
Save techbelly/1167850 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
require 'capybara/rails' | |
Capybara.default_driver = :selenium | |
class AddingPartsToGuidesTest < ActionDispatch::IntegrationTest | |
include Capybara::DSL | |
def teardown | |
DatabaseCleaner.clean | |
end | |
def switch_to_user(user_opts) | |
# Make sure that new user is the first in the database. Hackily. | |
# | |
current_users = User.all.to_a | |
unless user = User.first(conditions: {name: user_opts[:name]}) | |
user = User.new({:uid=>random_string(8)}.merge(user_opts)) | |
end | |
User.destroy_all | |
user.save | |
current_users.each do |u| | |
User.create(u.attributes) unless u.name == user.name | |
end | |
Capybara.reset_sessions! | |
user | |
end | |
def random_string(length,suffix="") | |
random_name = (0...length).map{65.+(rand(25)).chr}.join + suffix | |
end | |
test "Publishing a guide" do | |
without_panopticon_validation do | |
switch_to_user(:name=>"Author",:email=>"[email protected]") | |
random_name = random_string(8," GUIDE") | |
visit "/admin" | |
click_on 'Add new guide' | |
fill_in 'Name', :with => random_name | |
fill_in 'Slug', :with => 'test-guide' | |
click_on 'Create Guide' | |
click_on 'Untitled part' | |
within :css, '#parts div.part:first-of-type' do | |
fill_in 'Title' , :with => 'Part One' | |
fill_in 'Body', :with => 'Body text' | |
fill_in 'Slug', :with => 'part-one' | |
end | |
click_on 'Add new part' | |
within :css, '#parts div.part:nth-of-type(2)' do | |
fill_in 'Title' , :with => 'Part Two' | |
fill_in 'Body', :with => 'Body text' | |
fill_in 'Slug', :with => 'part-two' | |
end | |
within(:css, '#guide-controls') { click_on 'Save' } | |
click_on 'Add new part' | |
within :css, '#parts div.part:nth-of-type(3)' do | |
fill_in 'Title' , :with => 'Part Three' | |
fill_in 'Body', :with => 'Body text' | |
fill_in 'Slug', :with => 'part-three' | |
end | |
within(:css, '#guide-controls') { click_on 'Save' } | |
assert_equal 3, all(:css, '#parts > div.part').length | |
visit "/admin" | |
within(:css, '#new') { | |
assert page.has_content? random_name | |
click_on 'Edit this publication' | |
} | |
within(:css, '#guide-controls') { | |
click_on '2nd pair of eyes' | |
fill_in 'comment', :with => "Review this please" | |
click_on '2nd pair of eyes' | |
} | |
switch_to_user(:name=>"Reviewer",:email=>"[email protected]") | |
visit "/admin" | |
click_on 'Review Requested (1)' | |
within(:css, '#review-requested') { | |
assert page.has_content? random_name | |
click_on 'Edit this publication' | |
} | |
within(:css, '.workflow_buttons') { | |
click_on 'OK for publication' | |
} | |
fill_in 'comment', :with => "Review this please" | |
click_on 'OK for publication' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment