Created
May 27, 2014 16:06
-
-
Save rystraum/10f38bfcdabee25ccae3 to your computer and use it in GitHub Desktop.
This file contains 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" | |
describe FormsController, "#show" do | |
extend CitizenHelper | |
def setup | |
Form.delete_all | |
Question.delete_all | |
@form = create :active_form | |
end | |
redirect_to_login do | |
instance_variables.include? :@form # => false | |
get :show, id: @form.id | |
end | |
test "should be successful if the form is active" do | |
instance_variables.include? :@form # => true | |
end | |
end |
This file contains 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
module CitizenHelper | |
module SetupModule | |
def after_setup | |
@request.env["devise.mapping"] = Devise.mappings[:citizen] | |
@citizen = Citizen.first || create(:citizen) | |
@citizen.confirm! # important!!!! | |
sign_in @citizen | |
super | |
end | |
end | |
class MiniTest::Unit::TestCase | |
include SetupModule | |
end | |
def redirect_to_login | |
test "not logged in user should be directed to login page" do | |
sign_out @citizen | |
yield | |
assert_redirected_to new_citizen_session_path | |
refute_empty flash[:alert] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment