0
@@ -115,6 +115,17 @@ class Spec::Example::AwesomeExample < Spec::Example::Example
0
raise NotImplementedError
0
+ # it.validates_presence_of Foo, :name
0
+ def validates_presence_of(model, *attributes)
0
+ attributes.each do |attr|
0
+ desc, imp = assert_validates_presence_of(model, attr)
0
+ if @defined_description then create_sub_example desc, &imp
0
+ else @defined_description, @implementation = desc, imp end
0
@@variable_types.each do |collection_type, collection_op|
0
define_method "assigns_#{collection_type}" do |values|
0
@@ -217,22 +228,54 @@ protected
0
# it attempts to match the mime type using Mime::Type.lookup_by_extension.
0
def render_xml(record = nil, options = {}, &block)
0
+ render_xml_or_json :xml, record, options, &block
0
+ # Creates 3 examples: One to check that the given JSON was returned.
0
+ # It looks for two options: :status and :format.
0
+ # Checks that the json matches a given string
0
+ # it.renders(:json) { "{}" }
0
+ # Checks that the json matches @foo.to_json
0
+ # it.renders :json, :foo
0
+ # Checks that the json matches @foo.errors.to_json
0
+ # it.renders :json, "foo.errors"
0
+ # it.renders :json, :index, :status => :not_found
0
+ # it.renders :json, :index, :format => :json
0
+ # If :status is unset, it checks that that the response was a success.
0
+ # Otherwise it takes an integer or a symbol and matches the status code.
0
+ # If :format is unset, it checks that the action is Mime:HTML. Otherwise
0
+ # it attempts to match the mime type using Mime::Type.lookup_by_extension.
0
+ def render_json(record = nil, options = {}, &block)
0
+ render_xml_or_json :json, record, options, &block
0
+ def render_xml_or_json(format, record = nil, options = {}, &block)
0
- @defined_description = "renders
xml"
0
+ @defined_description = "renders
#{format}"
0
@implementation = lambda do
0
pieces = record.to_s.split(".")
0
record = instance_variable_get("@#{pieces.shift}")
0
record = record.send(pieces.shift) until pieces.empty?
0
- block ||= lambda { record.
to_xml }
0
+ block ||= lambda { record.
send("to_#{format}") }
0
acting.should have_text(block.call)
0
assert_status options[:status]
0
- assert_content_type options[:format] ||
:xml0
+ assert_content_type options[:format] ||
format0
def assigns_example_values(name, value)
0
@@ -277,7 +320,21 @@ protected
0
+ def assert_validates_presence_of(model, attribute)
0
+ ["requires #{attribute}", lambda do
0
+ @attributes.each do |key, value|
0
+ @record.send("#{key}=", value)
0
+ old_value = @record.send(attribute)
0
+ @record.send("#{attribute}=", nil)
0
+ @record.should_not be_valid
0
+ @record.errors.on(attribute).should_not be_nil
0
+ @record.send("#{attribute}=", old_value)
0
+ @record.should be_valid
0
def create_sub_example(desc, &imp)
0
@example_group.send(:example_objects) << Spec::Example::AwesomeExample.new(desc, @example_group, &imp) if @example_group
Comments
No one has commented yet.