Permalink
Browse files

add active_model_presence_validator helper and clean up test

  • Loading branch information...
guillaume belleguic authored and mjonuschat committed Apr 20, 2010
1 parent fd13bd6 commit 2769784d3dde6a3aa857d9ad045c30fc3f0fc228
Showing with 9 additions and 9 deletions.
  1. +3 −9 spec/input_spec.rb
  2. +6 −0 spec/spec_helper.rb
View
@@ -133,21 +133,17 @@
before do
@new_post.class.stub!(:method_defined?).with(:validators_on).and_return(true)
- @title_validation = mock('ActiveModel::Validations::PresenceValidator', :attributes => [:title], :options => {})
- @title_validation.stub!(:kind).and_return(:presence)
- @body_validation = mock('ActiveModel::Validations::PresenceValidator', :attributes => [:body], :options => {:if => true})
- @body_validation.stub!(:kind).and_return(:presence)
end
describe 'and validates_presence_of was called for the method' do
it 'should be required' do
@new_post.class.should_receive(:validators_on).with(:title).and_return([
- @title_validation
+ active_model_presence_validator([:title])
])
@new_post.class.should_receive(:validators_on).with(:body).and_return([
- @body_validation
+ active_model_presence_validator([:body], {:if => true})
])
form = semantic_form_for(@new_post) do |builder|
@@ -202,10 +198,8 @@
# TODO make a matcher for this?
def should_be_required(options)
- body_validation = mock('ActiveModel::Validations::PresenceValidator', :attributes => [:body], :options => options[:options])
- body_validation.stub!(:kind).and_return(:presence)
@new_post.class.should_receive(:validators_on).with(:body).and_return([
- body_validation
+ active_model_presence_validator([:body], options[:options])
])
form = semantic_form_for(@new_post) do |builder|
View
@@ -83,6 +83,12 @@ def default_input_type(column_type, column_name = :generic_column_name)
return @default_type
end
+ def active_model_presence_validator(attributes, options = {})
+ presence_validator = mock('ActiveModel::Validations::PresenceValidator', :attributes => attributes, :options => options)
+ presence_validator.stub!(:kind).and_return(:presence)
+ presence_validator
+ end
+
class ::Post
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)

0 comments on commit 2769784

Please sign in to comment.