This repository has been archived by the owner on Oct 22, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew
committed
Dec 1, 2009
1 parent
845a4b8
commit 2d92852
Showing
6 changed files
with
75 additions
and
67 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
require 'spec/rails/matchers/associations' | ||
|
||
require 'rspec_validation_expectations' | ||
require 'rspec_association_expectations' | ||
require 'rspec_other_expectations' | ||
require 'rspec_validation_expectations' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,5 @@ | ||
def it_should_validate_presence_of(*one_or_more_fields) | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate presence of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_presence_of } | ||
field_names = validations.collect(&:name) | ||
field_names.should include(field) | ||
end | ||
end | ||
end | ||
require 'spec/rails/matchers/associations' | ||
|
||
def it_should_validate_numericality_of(*one_or_more_fields) | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate numericality of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_numericality_of } | ||
field_names = validations.collect(&:name) | ||
field_names.should include(field) | ||
end | ||
end | ||
end | ||
|
||
def it_should_validate_uniqueness_of(*one_or_more_fields) | ||
options = one_or_more_fields.last.is_a?(Hash) ? one_or_more_fields.pop : {} | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate uniqueness of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_uniqueness_of } | ||
validations.collect(&:name).should include(field) | ||
validations.collect(&:options).should include(options) | ||
end | ||
end | ||
end | ||
|
||
def it_should_validate_inclusion_of(field_name, *args) | ||
model_name = described_type | ||
options = args.last.is_a?(Hash) ? args.pop : {} | ||
|
||
it "should validate inclusion of #{field_name} as one of #{options[:in].to_sentence(:connector => 'or', :skip_last_comma => true)}" do | ||
validations = model_name.reflect_on_all_validations | ||
validation = validations.detect {|v| v.macro == :validates_inclusion_of && v.name == field_name} | ||
|
||
unless validation.nil? | ||
validation.options[:in].sort.should == options[:in].sort | ||
end | ||
end | ||
end | ||
|
||
def it_should_be_createable *args | ||
model_name = described_type | ||
attributes = args.last.is_a?(Hash) ? args.last[:with] : {} | ||
|
||
it "should be creatable" do | ||
lambda {model_name.create(attributes)}.should change(model_name, :count).by(1) | ||
end | ||
end | ||
require 'rspec_validation_expectations/validation_expectations' | ||
require 'rspec_validation_expectations/association_expectations' | ||
require 'rspec_validation_expectations/other_expectations' |
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
lib/rspec_validation_expectations/validation_expectations.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
def it_should_validate_presence_of(*one_or_more_fields) | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate presence of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_presence_of } | ||
field_names = validations.collect(&:name) | ||
field_names.should include(field) | ||
end | ||
end | ||
end | ||
|
||
def it_should_validate_numericality_of(*one_or_more_fields) | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate numericality of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_numericality_of } | ||
field_names = validations.collect(&:name) | ||
field_names.should include(field) | ||
end | ||
end | ||
end | ||
|
||
def it_should_validate_uniqueness_of(*one_or_more_fields) | ||
options = one_or_more_fields.last.is_a?(Hash) ? one_or_more_fields.pop : {} | ||
model_name = described_type | ||
one_or_more_fields.each do |field| | ||
it "should validate uniqueness of #{field.to_s.humanize.downcase}" do | ||
validations = model_name.reflect_on_all_validations | ||
validations = validations.select { |e| e.macro == :validates_uniqueness_of } | ||
validations.collect(&:name).should include(field) | ||
validations.collect(&:options).should include(options) | ||
end | ||
end | ||
end | ||
|
||
def it_should_validate_inclusion_of(field_name, *args) | ||
model_name = described_type | ||
options = args.last.is_a?(Hash) ? args.pop : {} | ||
|
||
it "should validate inclusion of #{field_name} as one of #{options[:in].to_sentence(:connector => 'or', :skip_last_comma => true)}" do | ||
validations = model_name.reflect_on_all_validations | ||
validation = validations.detect {|v| v.macro == :validates_inclusion_of && v.name == field_name} | ||
|
||
unless validation.nil? | ||
validation.options[:in].sort.should == options[:in].sort | ||
end | ||
end | ||
end | ||
|
||
def it_should_be_createable *args | ||
model_name = described_type | ||
attributes = args.last.is_a?(Hash) ? args.last[:with] : {} | ||
|
||
it "should be creatable" do | ||
lambda {model_name.create(attributes)}.should change(model_name, :count).by(1) | ||
end | ||
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