Skip to content

Instantly share code, notes, and snippets.

@rystraum
Created May 27, 2014 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rystraum/10f38bfcdabee25ccae3 to your computer and use it in GitHub Desktop.
Save rystraum/10f38bfcdabee25ccae3 to your computer and use it in GitHub Desktop.
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
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