adopt-a-hydrant/test/controllers/info_window_controller_test.rb

72 lines
2.2 KiB
Ruby
Raw Normal View History

2011-05-31 11:12:02 +00:00
require 'test_helper'
class InfoWindowControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@thing = things(:thing_1)
2011-05-31 11:12:02 +00:00
@user = users(:erik)
end
2015-06-01 18:47:16 +00:00
test 'should thank the user if the hydrant is adopted by the user' do
2011-05-31 11:12:02 +00:00
sign_in @user
@thing.user_id = @user.id
@thing.save!
2014-03-25 09:47:44 +00:00
get :index, thing_id: @thing.id
assert_not_nil assigns :thing
2011-05-31 11:12:02 +00:00
assert_response :success
assert_template 'users/thank_you'
assert_select 'h2', 'Thank you for adopting this hydrant!'
assert_select 'form#abandon_form' do
2014-04-01 08:15:29 +00:00
assert_select '[action=?]', '/things'
2011-05-31 11:12:02 +00:00
assert_select '[method=?]', 'post'
end
assert_select 'input[name="_method"]' do
assert_select '[type=?]', 'hidden'
assert_select '[value=?]', 'put'
end
assert_select 'input[name="commit"]' do
assert_select '[type=?]', 'submit'
assert_select '[value=?]', 'Abandon this hydrant'
end
end
test 'should show the profile if the hydrant is adopted' do
@thing.user_id = @user.id
@thing.save!
2014-03-25 09:47:44 +00:00
get :index, thing_id: @thing.id
assert_not_nil assigns :thing
2011-05-31 11:12:02 +00:00
assert_response :success
assert_template 'users/profile'
2011-09-15 01:56:46 +00:00
assert_select 'h2', /This hydrant has been adopted\s+by #{@user.name}\s+of #{@user.organization}/
2011-05-31 11:12:02 +00:00
end
test 'should show adoption form if hydrant is not adopted' do
sign_in @user
2014-03-25 09:47:44 +00:00
get :index, thing_id: @thing.id
assert_not_nil assigns :thing
2011-05-31 11:12:02 +00:00
assert_response :success
assert_template :adopt
assert_select 'h2', 'Adopt this Hydrant'
assert_select 'form#adoption_form' do
2014-04-01 08:15:29 +00:00
assert_select '[action=?]', '/things'
2011-05-31 11:12:02 +00:00
assert_select '[method=?]', 'post'
end
assert_select 'input[name="_method"]' do
assert_select '[type=?]', 'hidden'
assert_select '[value=?]', 'put'
end
assert_select 'input[name="commit"]' do
assert_select '[type=?]', 'submit'
assert_select '[value=?]', 'Adopt!'
end
end
test 'should show sign-in form if signed out' do
2014-03-25 09:47:44 +00:00
get :index, thing_id: @thing.id
assert_not_nil assigns :thing
2011-05-31 11:12:02 +00:00
assert_response :success
2011-12-25 07:23:19 +00:00
assert_template 'users/sign_in'
assert_select 'h2', 'Sign in to adopt this Hydrant'
2011-05-31 11:12:02 +00:00
end
end