Module: Clearance::Test::TestHelper::ClassMethods
- Defined in:
- lib/clearance/test/test_helper.rb
Instance Method Summary collapse
- #form_http_method(http_method) ⇒ Object
- #logged_in_user_context(&blk) ⇒ Object
- #public_context(&blk) ⇒ Object
- #should_deny_access(opts = {}) ⇒ Object
- #should_deny_access_on(command, opts = {}) ⇒ Object
-
#should_have_form(opts) ⇒ Object
should_have_form :action => ‘admin_users_path’, :method => :get, :fields => { ‘email’ => :text } TODO: http_method should be pulled out.
Instance Method Details
#form_http_method(http_method) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/clearance/test/test_helper.rb', line 65 def form_http_method(http_method) http_method = http_method.nil? ? 'post' : http_method.to_s if http_method == "post" || http_method == "get" return http_method, nil else return "post", http_method end end |
#logged_in_user_context(&blk) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/clearance/test/test_helper.rb', line 74 def logged_in_user_context(&blk) context "A logged in user" do setup do @user = Factory :user login_as @user end merge_block(&blk) end end |
#public_context(&blk) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/clearance/test/test_helper.rb', line 84 def public_context(&blk) context "The public" do setup { logout } merge_block(&blk) end end |
#should_deny_access(opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/clearance/test/test_helper.rb', line 33 def should_deny_access(opts = {}) opts[:redirect] ||= "new_session_path" should_redirect_to opts[:redirect] if opts[:flash] should_set_the_flash_to opts[:flash] else should_not_set_the_flash end end |
#should_deny_access_on(command, opts = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/clearance/test/test_helper.rb', line 25 def should_deny_access_on(command, opts = {}) context "on #{command}" do setup { eval command } should_deny_access(opts) end end |
#should_have_form(opts) ⇒ Object
should_have_form :action => ‘admin_users_path’,
:method => :get,
:fields => { 'email' => :text }
TODO: http_method should be pulled out
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/clearance/test/test_helper.rb', line 47 def should_have_form(opts) model = self.name.gsub(/ControllerTest$/, '').singularize.downcase model = model[model.rindex('::')+2..model.size] if model.include?('::') http_method, hidden_http_method = form_http_method opts[:method] should "have a #{model} form" do assert_select "form[action=?][method=#{http_method}]", eval(opts[:action]) do if hidden_http_method assert_select "input[type=hidden][name=_method][value=#{hidden_http_method}]" end opts[:fields].each do |attribute, type| attribute = attribute.is_a?(Symbol) ? "#{model}[#{attribute.to_s}]" : attribute assert_select "input[type=#{type.to_s}][name=?]", attribute end assert_select "input[type=submit]" end end end |