Module: Clearance::TestHelper::ClassMethods

Defined in:
lib/clearance/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#logged_in_user_context(user_name = nil, &blk) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/clearance/test_helper.rb', line 63

def logged_in_user_context(user_name = nil, &blk)
  context "When logged in as a user" do
    setup do
      user = user_name ? instance_variable_get("@#{user_name}") : Factory(:user)
      assert @current_user = (user)
    end
    merge_block(&blk)
  end
end

#should_deny_access_on(command, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/clearance/test_helper.rb', line 24

def should_deny_access_on(command, opts = {})
  opts[:redirect] ||= "login_url"

  context "on #{command}" do
    setup { eval command }
    should_redirect_to opts[:redirect]
    if opts[:flash]
      should_set_the_flash_to opts[:flash]
    else
      should_not_set_the_flash
    end
  end
end

#should_filter(*keys) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/clearance/test_helper.rb', line 38

def should_filter(*keys)
  keys.each do |key|
    should "filter #{key}" do
      assert @controller.respond_to?(:filter_parameters),
        "The key #{key} is not filtered"
      filtered = @controller.send(:filter_parameters, {key.to_s => key.to_s})
      assert_equal '[FILTERED]', filtered[key.to_s],
        "The key #{key} is not filtered"
    end
  end
end

#should_have_user_formObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/clearance/test_helper.rb', line 50

def should_have_user_form
  should "have the user form" do
    assert_select "form" do
      %w(name email openid_url).each do |field|
        assert_select "input[type=text][name=?]", "user[#{field}]"
      end
      %w(password password_confirmation).each do |field|
        assert_select "input[type=password][name=?]", "user[#{field}]"
      end
    end
  end
end