Created
March 14, 2009 19:27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RequireBodyCopyMacros | |
def should_require_body_copy | |
context "create" do | |
should_display_error_if_body_not_set :post_create | |
end | |
context "update" do | |
should_display_error_if_body_not_set :put_update | |
end | |
context "preview" do | |
should_display_error_if_body_not_set :put_update, "Preview" | |
end | |
end | |
def should_display_error_if_body_not_set(method, button="Save") | |
should "display error if body not set" do | |
send(method, button, :page => { :body => "" }) | |
assert_select "h2", :text => /error/ | |
end | |
end | |
end | |
class Test::Unit::TestCase | |
extend RequireBodyCopyMacros | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def post_create(button, options={}) | |
options[:page] ||= {} | |
options[:page].reverse_merge!(:heading => "A page", :body => "Body copy") | |
post :create, options.merge(:commit => button) | |
end | |
def put_update(button, options={}) | |
options[:page] ||= {} | |
options[:page].reverse_merge!(:heading => "A page") | |
put :update, options.merge!(:id => @article.to_param, :commit => button) | |
end | |
context "Article controller" do | |
setup do | |
login | |
@model_class = Article | |
@model = @article = Factory(:published_article) | |
@section = Factory(:section) | |
end | |
should_behave_like_admin_controller | |
should_require_body_copy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment