diff --git a/test/shoulda_macros/forms.rb b/test/shoulda_macros/forms.rb index 2f7aa40..1bd8561 100644 --- a/test/shoulda_macros/forms.rb +++ b/test/shoulda_macros/forms.rb @@ -1,31 +1,4 @@ class Test::Unit::TestCase - def self.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 - - def self.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 - # assert_form posts_url, :put do # assert_text_field :post, :title # assert_text_area :post, :body @@ -56,26 +29,34 @@ class Test::Unit::TestCase assert_select "input[type=submit]" end - # TODO: default to test the label, provide :label => false option - def assert_text_field(model, attribute) + def assert_text_field(model, attribute, opts = {}) + unless opts[:label] == false + assert_label model, attribute + end assert_select "input[type=text][name=?]", "#{model.to_s}[#{attribute.to_s}]" end - # TODO: default to test the label, provide :label => false option - def assert_text_area(model, attribute) + def assert_text_area(model, attribute, opts = {}) + unless opts[:label] == false + assert_label model, attribute + end assert_select "textarea[name=?]", "#{model.to_s}[#{attribute.to_s}]" end - # TODO: default to test the label, provide :label => false option - def assert_password_field(model, attribute) + def assert_password_field(model, attribute, opts = {}) + unless opts[:label] == false + assert_label model, attribute + end assert_select "input[type=password][name=?]", "#{model.to_s}[#{attribute.to_s}]" end - # TODO: default to test the label, provide :label => false option - def assert_radio_button(model, attribute) + def assert_radio_button(model, attribute, opts = {}) + unless opts[:label] == false + assert_label model, attribute + end assert_select "input[type=radio][name=?]", "#{model.to_s}[#{attribute.to_s}]" end diff --git a/test/shoulda_macros/pagination.rb b/test/shoulda_macros/pagination.rb index 7677388..c22b8a8 100644 --- a/test/shoulda_macros/pagination.rb +++ b/test/shoulda_macros/pagination.rb @@ -1,8 +1,8 @@ class Test::Unit::TestCase # Example: - # context "a GET to index logged in as admin" do + # context "a GET to index signed in as admin" do # setup do - # login_as_admin + # sign_in_as Factory(:admin_user) # get :index # end # should_paginate_collection :users @@ -10,38 +10,38 @@ class Test::Unit::TestCase # end def self.should_paginate_collection(collection_name) should "paginate #{collection_name}" do - assert collection = assigns(collection_name), + assert collection = assigns(collection_name), "Controller isn't assigning to @#{collection_name.to_s}." - assert_kind_of WillPaginate::Collection, collection, + assert_kind_of WillPaginate::Collection, collection, "@#{collection_name.to_s} isn't a WillPaginate collection." end end - + def self.should_display_pagination should "display pagination" do - assert_select "div.pagination", { :minimum => 1 }, + assert_select "div.pagination", { :minimum => 1 }, "View isn't displaying pagination. Add <%= will_paginate @collection %>." end end - + # Example: - # context "a GET to index not logged in as admin" do + # context "a GET to index not signed in as admin" do # setup { get :index } # should_not_paginate_collection :users # should_not_display_pagination # end def self.should_not_paginate_collection(collection_name) should "not paginate #{collection_name}" do - assert collection = assigns(collection_name), + assert collection = assigns(collection_name), "Controller isn't assigning to @#{collection_name.to_s}." - assert_not_equal WillPaginate::Collection, collection.class, + assert_not_equal WillPaginate::Collection, collection.class, "@#{collection_name.to_s} is a WillPaginate collection." end end - + def self.should_not_display_pagination should "not display pagination" do - assert_select "div.pagination", { :count => 0 }, + assert_select "div.pagination", { :count => 0 }, "View is displaying pagination. Check your logic." end end -- libgit2 0.21.2