Module: Clearance::TestHelper::ClassMethods

Defined in:
lib/clearance/test/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#logged_in_user_context(&blk) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/clearance/test/test_helper.rb', line 60

def logged_in_user_context(&blk)
  context "A logged in user" do
    setup do
      @user = Factory :user
       @user
    end
    merge_block(&blk)
  end
end

#public_context(&blk) ⇒ Object



70
71
72
73
74
75
# File 'lib/clearance/test/test_helper.rb', line 70

def public_context(&blk)
  context "The public" do
    setup { logout }
    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/test_helper.rb', line 24

def should_deny_access_on(command, opts = {})
  opts[:redirect] ||= "root_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/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
# File 'lib/clearance/test/test_helper.rb', line 50

def should_have_user_form
  should "have user form" do
    assert_select "form" do
      assert_select "input[type=text][name=?]", "user[email]"
      assert_select "input[type=password][name=?]", "user[password]"
      assert_select "input[type=password][name=?]", "user[password_confirmation]"
    end
  end
end