remarkable_activerecord 3.1.8 → 3.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +140 -138
- data/LICENSE +20 -20
- data/README +80 -80
- data/lib/remarkable_activerecord.rb +29 -29
- data/lib/remarkable_activerecord/base.rb +248 -237
- data/lib/remarkable_activerecord/describe.rb +27 -27
- data/lib/remarkable_activerecord/human_names.rb +36 -36
- data/lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +59 -59
- data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +85 -94
- data/lib/remarkable_activerecord/matchers/association_matcher.rb +283 -283
- data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +68 -68
- data/lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb +38 -38
- data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +73 -73
- data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +85 -85
- data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +50 -50
- data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +97 -97
- data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
- data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +53 -53
- data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +52 -52
- data/lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb +150 -150
- data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +181 -181
- data/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb +29 -29
- data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +233 -233
- data/locale/en.yml +261 -261
- data/spec/accept_nested_attributes_for_matcher_spec.rb +1 -1
- data/spec/allow_mass_assignment_of_matcher_spec.rb +90 -82
- data/spec/allow_values_for_matcher_spec.rb +72 -63
- data/spec/association_matcher_spec.rb +612 -612
- data/spec/describe_spec.rb +3 -3
- data/spec/have_column_matcher_spec.rb +73 -73
- data/spec/have_default_scope_matcher_spec.rb +1 -1
- data/spec/have_index_matcher_spec.rb +87 -87
- data/spec/have_readonly_attributes_matcher_spec.rb +47 -47
- data/spec/have_scope_matcher_spec.rb +77 -77
- data/spec/model_builder.rb +101 -101
- data/spec/rcov.opts +1 -1
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +27 -27
- data/spec/validate_acceptance_of_matcher_spec.rb +68 -68
- data/spec/validate_associated_matcher_spec.rb +121 -121
- data/spec/validate_confirmation_of_matcher_spec.rb +58 -58
- data/spec/validate_length_of_matcher_spec.rb +218 -218
- data/spec/validate_numericality_of_matcher_spec.rb +179 -179
- data/spec/validate_presence_of_matcher_spec.rb +56 -56
- data/spec/validate_uniqueness_of_matcher_spec.rb +164 -164
- metadata +5 -5
@@ -1,85 +1,85 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'have_scope' do
|
4
|
-
include ModelBuilder
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@model = define_model :product, :title => :string, :category => :string do
|
8
|
-
named_scope :recent, :order => 'created_at DESC'
|
9
|
-
named_scope :latest, lambda {|c| {:limit => c}}
|
10
|
-
named_scope :since, lambda {|t| {:conditions => ['created_at > ?', t]}}
|
11
|
-
named_scope :between, lambda { |a, b| { :conditions => [ 'created_at > ? and created_at < ?', a, b ] } }
|
12
|
-
|
13
|
-
def self.beginning(c)
|
14
|
-
scoped(:offset => c)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.null
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'messages' do
|
24
|
-
|
25
|
-
it 'should contain a description' do
|
26
|
-
matcher = have_scope(:title)
|
27
|
-
matcher.description.should == 'have to scope itself to {} when :title is called'
|
28
|
-
|
29
|
-
matcher.with(1)
|
30
|
-
matcher.description.should == 'have to scope itself to {} when :title is called with [1] as argument'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should set is_scope? message' do
|
34
|
-
matcher = have_scope(:null)
|
35
|
-
matcher.matches?(@model)
|
36
|
-
matcher.failure_message.should == 'Expected :null when called on Product return an instance of ActiveRecord::NamedScope::Scope'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should set options_match? message' do
|
40
|
-
matcher = have_scope(:recent, :conditions => {:special => true})
|
41
|
-
matcher.matches?(@model)
|
42
|
-
matcher.failure_message.should == 'Expected :recent when called on Product scope to {:conditions=>{:special=>true}}, got {:order=>"created_at DESC"}'
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'matchers' do
|
48
|
-
it { should have_scope(:recent) }
|
49
|
-
it { should have_scope(:recent, :order => 'created_at DESC') }
|
50
|
-
|
51
|
-
it { should have_scope(:latest).with(10).limit(10) }
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'have_scope' do
|
4
|
+
include ModelBuilder
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@model = define_model :product, :title => :string, :category => :string do
|
8
|
+
named_scope :recent, :order => 'created_at DESC'
|
9
|
+
named_scope :latest, lambda {|c| {:limit => c}}
|
10
|
+
named_scope :since, lambda {|t| {:conditions => ['created_at > ?', t]}}
|
11
|
+
named_scope :between, lambda { |a, b| { :conditions => [ 'created_at > ? and created_at < ?', a, b ] } }
|
12
|
+
|
13
|
+
def self.beginning(c)
|
14
|
+
scoped(:offset => c)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.null
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'messages' do
|
24
|
+
|
25
|
+
it 'should contain a description' do
|
26
|
+
matcher = have_scope(:title)
|
27
|
+
matcher.description.should == 'have to scope itself to {} when :title is called'
|
28
|
+
|
29
|
+
matcher.with(1)
|
30
|
+
matcher.description.should == 'have to scope itself to {} when :title is called with [1] as argument'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set is_scope? message' do
|
34
|
+
matcher = have_scope(:null)
|
35
|
+
matcher.matches?(@model)
|
36
|
+
matcher.failure_message.should == 'Expected :null when called on Product return an instance of ActiveRecord::NamedScope::Scope'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set options_match? message' do
|
40
|
+
matcher = have_scope(:recent, :conditions => {:special => true})
|
41
|
+
matcher.matches?(@model)
|
42
|
+
matcher.failure_message.should == 'Expected :recent when called on Product scope to {:conditions=>{:special=>true}}, got {:order=>"created_at DESC"}'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'matchers' do
|
48
|
+
it { should have_scope(:recent) }
|
49
|
+
it { should have_scope(:recent, :order => 'created_at DESC') }
|
50
|
+
|
51
|
+
it { should have_scope(:latest).with(10).limit(10) }
|
52
52
|
it { should have_scope(:beginning).with(10).offset(10) }
|
53
|
-
it { should have_scope(:since).with(false).conditions(["created_at > ?", false]) }
|
54
|
-
it { should have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(0)]) }
|
55
|
-
it { should have_scope(:between).with(2, 10).conditions(["created_at > ? and created_at < ?", 2, 10]) }
|
56
|
-
|
53
|
+
it { should have_scope(:since).with(false).conditions(["created_at > ?", false]) }
|
54
|
+
it { should have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(0)]) }
|
55
|
+
it { should have_scope(:between).with(2, 10).conditions(["created_at > ? and created_at < ?", 2, 10]) }
|
56
|
+
|
57
57
|
it { should_not have_scope(:null) }
|
58
|
-
it { should_not have_scope(:latest).with(5).limit(10) }
|
59
|
-
it { should_not have_scope(:beginning).with(5).offset(10) }
|
60
|
-
it { should_not have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(1)]) }
|
61
|
-
it { should_not have_scope(:between).with(2, 10).conditions(["updated_at > ? and updated_at < ?", 2, 10]) }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe 'macros' do
|
65
|
-
should_have_scope :recent
|
66
|
-
should_have_scope :recent, :order => 'created_at DESC'
|
67
|
-
|
68
|
-
should_have_scope :latest, :with => 10, :limit => 10
|
69
|
-
should_have_scope :beginning, :with => 10, :offset => 10
|
58
|
+
it { should_not have_scope(:latest).with(5).limit(10) }
|
59
|
+
it { should_not have_scope(:beginning).with(5).offset(10) }
|
60
|
+
it { should_not have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(1)]) }
|
61
|
+
it { should_not have_scope(:between).with(2, 10).conditions(["updated_at > ? and updated_at < ?", 2, 10]) }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'macros' do
|
65
|
+
should_have_scope :recent
|
66
|
+
should_have_scope :recent, :order => 'created_at DESC'
|
67
|
+
|
68
|
+
should_have_scope :latest, :with => 10, :limit => 10
|
69
|
+
should_have_scope :beginning, :with => 10, :offset => 10
|
70
70
|
should_have_scope :since, :with => false, :conditions => ["created_at > ?", false]
|
71
|
-
should_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(0)]
|
71
|
+
should_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(0)]
|
72
72
|
should_have_scope :between, :with => [ 2, 10 ], :conditions => [ "created_at > ? and created_at < ?", 2, 10 ]
|
73
73
|
|
74
74
|
should_have_scope :between do |m|
|
75
75
|
m.with(2, 10)
|
76
76
|
m.conditions([ "created_at > ? and created_at < ?", 2, 10 ])
|
77
|
-
end
|
78
|
-
|
79
|
-
should_not_have_scope :null
|
80
|
-
should_not_have_scope :latest, :with => 5, :limit => 10
|
81
|
-
should_not_have_scope :beginning, :with => 5, :offset => 10
|
82
|
-
should_not_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(1)]
|
83
|
-
should_not_have_scope :between, :with => [ 2, 10 ], :conditions => [ "updated_at > ? and updated_at < ?", 2, 10 ]
|
84
|
-
end
|
85
|
-
end
|
77
|
+
end
|
78
|
+
|
79
|
+
should_not_have_scope :null
|
80
|
+
should_not_have_scope :latest, :with => 5, :limit => 10
|
81
|
+
should_not_have_scope :beginning, :with => 5, :offset => 10
|
82
|
+
should_not_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(1)]
|
83
|
+
should_not_have_scope :between, :with => [ 2, 10 ], :conditions => [ "updated_at > ? and updated_at < ?", 2, 10 ]
|
84
|
+
end
|
85
|
+
end
|
data/spec/model_builder.rb
CHANGED
@@ -1,101 +1,101 @@
|
|
1
|
-
# This is based on Shoulda model builder for Test::Unit.
|
2
|
-
#
|
3
|
-
module ModelBuilder
|
4
|
-
def self.included(base)
|
5
|
-
return unless base.name =~ /^Spec/
|
6
|
-
|
7
|
-
base.class_eval do
|
8
|
-
after(:each) do
|
9
|
-
if @defined_constants
|
10
|
-
@defined_constants.each do |class_name|
|
11
|
-
Object.send(:remove_const, class_name)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if @created_tables
|
16
|
-
@created_tables.each do |table_name|
|
17
|
-
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
base.extend ClassMethods
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_table(table_name, &block)
|
27
|
-
connection = ActiveRecord::Base.connection
|
28
|
-
|
29
|
-
begin
|
30
|
-
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
31
|
-
connection.create_table(table_name, &block)
|
32
|
-
@created_tables ||= []
|
33
|
-
@created_tables << table_name
|
34
|
-
connection
|
35
|
-
rescue Exception => e
|
36
|
-
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
37
|
-
raise e
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def define_constant(class_name, base, &block)
|
42
|
-
class_name = class_name.to_s.camelize
|
43
|
-
|
44
|
-
klass = Class.new(base)
|
45
|
-
Object.const_set(class_name, klass)
|
46
|
-
|
47
|
-
klass.class_eval(&block) if block_given?
|
48
|
-
|
49
|
-
@defined_constants ||= []
|
50
|
-
@defined_constants << class_name
|
51
|
-
|
52
|
-
klass
|
53
|
-
end
|
54
|
-
|
55
|
-
def define_model_class(class_name, &block)
|
56
|
-
define_constant(class_name, ActiveRecord::Base, &block)
|
57
|
-
end
|
58
|
-
|
59
|
-
def define_model(name, columns = {}, &block)
|
60
|
-
class_name = name.to_s.pluralize.classify
|
61
|
-
table_name = class_name.tableize
|
62
|
-
|
63
|
-
table = columns.delete(:table) || lambda {|table|
|
64
|
-
columns.each do |name, type|
|
65
|
-
table.column name, *type
|
66
|
-
end
|
67
|
-
}
|
68
|
-
|
69
|
-
create_table(table_name, &table)
|
70
|
-
|
71
|
-
klass = define_model_class(class_name, &block)
|
72
|
-
instance = klass.new
|
73
|
-
|
74
|
-
self.class.subject { instance } if self.class.respond_to?(:subject)
|
75
|
-
instance
|
76
|
-
end
|
77
|
-
|
78
|
-
module ClassMethods
|
79
|
-
# This is a macro to run validations of boolean optionals such as :allow_nil
|
80
|
-
# and :allow_blank. This macro tests all scenarios. The specs must have a
|
81
|
-
# define_and_validate method defined.
|
82
|
-
#
|
83
|
-
def create_optional_boolean_specs(optional, base, options={})
|
84
|
-
base.describe "with #{optional} option" do
|
85
|
-
it { should define_and_validate(options.merge(optional => true)).send(optional) }
|
86
|
-
it { should define_and_validate(options.merge(optional => false)).send(optional, false) }
|
87
|
-
it { should_not define_and_validate(options.merge(optional => true)).send(optional, false) }
|
88
|
-
it { should_not define_and_validate(options.merge(optional => false)).send(optional) }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def create_message_specs(base)
|
93
|
-
base.describe "with message option" do
|
94
|
-
it { should define_and_validate(:message => 'valid_message').message('valid_message') }
|
95
|
-
it { should_not define_and_validate(:message => 'not_valid').message('valid_message') }
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
1
|
+
# This is based on Shoulda model builder for Test::Unit.
|
2
|
+
#
|
3
|
+
module ModelBuilder
|
4
|
+
def self.included(base)
|
5
|
+
return unless base.name =~ /^Spec/
|
6
|
+
|
7
|
+
base.class_eval do
|
8
|
+
after(:each) do
|
9
|
+
if @defined_constants
|
10
|
+
@defined_constants.each do |class_name|
|
11
|
+
Object.send(:remove_const, class_name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if @created_tables
|
16
|
+
@created_tables.each do |table_name|
|
17
|
+
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
base.extend ClassMethods
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_table(table_name, &block)
|
27
|
+
connection = ActiveRecord::Base.connection
|
28
|
+
|
29
|
+
begin
|
30
|
+
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
31
|
+
connection.create_table(table_name, &block)
|
32
|
+
@created_tables ||= []
|
33
|
+
@created_tables << table_name
|
34
|
+
connection
|
35
|
+
rescue Exception => e
|
36
|
+
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def define_constant(class_name, base, &block)
|
42
|
+
class_name = class_name.to_s.camelize
|
43
|
+
|
44
|
+
klass = Class.new(base)
|
45
|
+
Object.const_set(class_name, klass)
|
46
|
+
|
47
|
+
klass.class_eval(&block) if block_given?
|
48
|
+
|
49
|
+
@defined_constants ||= []
|
50
|
+
@defined_constants << class_name
|
51
|
+
|
52
|
+
klass
|
53
|
+
end
|
54
|
+
|
55
|
+
def define_model_class(class_name, &block)
|
56
|
+
define_constant(class_name, ActiveRecord::Base, &block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def define_model(name, columns = {}, &block)
|
60
|
+
class_name = name.to_s.pluralize.classify
|
61
|
+
table_name = class_name.tableize
|
62
|
+
|
63
|
+
table = columns.delete(:table) || lambda {|table|
|
64
|
+
columns.each do |name, type|
|
65
|
+
table.column name, *type
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
create_table(table_name, &table)
|
70
|
+
|
71
|
+
klass = define_model_class(class_name, &block)
|
72
|
+
instance = klass.new
|
73
|
+
|
74
|
+
self.class.subject { instance } if self.class.respond_to?(:subject)
|
75
|
+
instance
|
76
|
+
end
|
77
|
+
|
78
|
+
module ClassMethods
|
79
|
+
# This is a macro to run validations of boolean optionals such as :allow_nil
|
80
|
+
# and :allow_blank. This macro tests all scenarios. The specs must have a
|
81
|
+
# define_and_validate method defined.
|
82
|
+
#
|
83
|
+
def create_optional_boolean_specs(optional, base, options={})
|
84
|
+
base.describe "with #{optional} option" do
|
85
|
+
it { should define_and_validate(options.merge(optional => true)).send(optional) }
|
86
|
+
it { should define_and_validate(options.merge(optional => false)).send(optional, false) }
|
87
|
+
it { should_not define_and_validate(options.merge(optional => true)).send(optional, false) }
|
88
|
+
it { should_not define_and_validate(options.merge(optional => false)).send(optional) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_message_specs(base)
|
93
|
+
base.describe "with message option" do
|
94
|
+
it { should define_and_validate(:message => 'valid_message').message('valid_message') }
|
95
|
+
it { should_not define_and_validate(:message => 'not_valid').message('valid_message') }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
data/spec/rcov.opts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--exclude "spec/*,gems/*"
|
1
|
+
--exclude "spec/*,gems/*"
|
2
2
|
--rails
|
data/spec/spec.opts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
--colour
|
2
|
-
--format progress
|
3
|
-
--loadby mtime
|
4
|
-
--reverse
|
1
|
+
--colour
|
2
|
+
--format progress
|
3
|
+
--loadby mtime
|
4
|
+
--reverse
|
data/spec/spec_helper.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
|
4
|
-
RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.
|
5
|
-
|
6
|
-
gem 'activesupport', RAILS_VERSION
|
7
|
-
require 'active_support'
|
8
|
-
|
9
|
-
gem 'activerecord', RAILS_VERSION
|
10
|
-
require 'active_record'
|
11
|
-
|
12
|
-
# Configure ActiveRecord connection
|
13
|
-
ActiveRecord::Base.establish_connection(
|
14
|
-
:adapter => 'sqlite3',
|
15
|
-
:database => ':memory:'
|
16
|
-
)
|
17
|
-
|
18
|
-
# Load Remarkable core on place to avoid gem to be loaded
|
19
|
-
dir = File.dirname(__FILE__)
|
20
|
-
require File.join(dir, '..', '..', 'remarkable', 'lib', 'remarkable')
|
21
|
-
|
22
|
-
# Load Remarkable ActiveRecord
|
23
|
-
require File.join(dir, 'model_builder')
|
24
|
-
require File.join(dir, '..', 'lib', 'remarkable_activerecord')
|
25
|
-
|
26
|
-
# Include matchers
|
27
|
-
Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.3'
|
5
|
+
|
6
|
+
gem 'activesupport', RAILS_VERSION
|
7
|
+
require 'active_support'
|
8
|
+
|
9
|
+
gem 'activerecord', RAILS_VERSION
|
10
|
+
require 'active_record'
|
11
|
+
|
12
|
+
# Configure ActiveRecord connection
|
13
|
+
ActiveRecord::Base.establish_connection(
|
14
|
+
:adapter => 'sqlite3',
|
15
|
+
:database => ':memory:'
|
16
|
+
)
|
17
|
+
|
18
|
+
# Load Remarkable core on place to avoid gem to be loaded
|
19
|
+
dir = File.dirname(__FILE__)
|
20
|
+
require File.join(dir, '..', '..', 'remarkable', 'lib', 'remarkable')
|
21
|
+
|
22
|
+
# Load Remarkable ActiveRecord
|
23
|
+
require File.join(dir, 'model_builder')
|
24
|
+
require File.join(dir, '..', 'lib', 'remarkable_activerecord')
|
25
|
+
|
26
|
+
# Include matchers
|
27
|
+
Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
|
@@ -1,68 +1,68 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'validate_acceptance_of' do
|
4
|
-
include ModelBuilder
|
5
|
-
|
6
|
-
# Defines a model, create a validation and returns a raw matcher
|
7
|
-
def define_and_validate(options={})
|
8
|
-
@model = define_model :user, :eula => :string, :terms => :string, :name => :string do
|
9
|
-
validates_acceptance_of :eula, :terms, options
|
10
|
-
end
|
11
|
-
|
12
|
-
validate_acceptance_of(:eula, :terms)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'messages' do
|
16
|
-
before(:each){ @matcher = define_and_validate }
|
17
|
-
|
18
|
-
it 'should contain a description' do
|
19
|
-
@matcher.description.should == 'require eula and terms to be accepted'
|
20
|
-
|
21
|
-
@matcher.accept('true')
|
22
|
-
@matcher.description.should == 'require eula and terms to be accepted with value "true"'
|
23
|
-
|
24
|
-
@matcher.allow_nil
|
25
|
-
@matcher.description.should == 'require eula and terms to be accepted with value "true" and allowing nil values'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should set requires_acceptance? message' do
|
29
|
-
@matcher = validate_acceptance_of(:name)
|
30
|
-
@matcher.matches?(@model)
|
31
|
-
@matcher.failure_message.should == 'Expected User to be invalid if name is not accepted'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should set accept_is_valid? message' do
|
35
|
-
@matcher.accept('accept_value').matches?(@model)
|
36
|
-
@matcher.failure_message.should == 'Expected User to be valid when eula is accepted with value "accept_value"'
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'matchers' do
|
42
|
-
|
43
|
-
describe 'without options' do
|
44
|
-
before(:each){ define_and_validate }
|
45
|
-
|
46
|
-
it { should validate_acceptance_of(:eula) }
|
47
|
-
it { should validate_acceptance_of(:eula, :terms) }
|
48
|
-
it { should_not validate_acceptance_of(:eula, :name) }
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'with accept as option' do
|
52
|
-
it { should define_and_validate(:accept => 'accept_value').accept('accept_value') }
|
53
|
-
it { should_not define_and_validate(:accept => 'another_value').accept('a_value') }
|
54
|
-
end
|
55
|
-
|
56
|
-
create_message_specs(self)
|
57
|
-
create_optional_boolean_specs(:allow_nil, self)
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'macros' do
|
61
|
-
before(:each){ define_and_validate }
|
62
|
-
|
63
|
-
should_validate_acceptance_of :eula
|
64
|
-
should_validate_acceptance_of :eula, :terms
|
65
|
-
should_not_validate_acceptance_of :eula, :name
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'validate_acceptance_of' do
|
4
|
+
include ModelBuilder
|
5
|
+
|
6
|
+
# Defines a model, create a validation and returns a raw matcher
|
7
|
+
def define_and_validate(options={})
|
8
|
+
@model = define_model :user, :eula => :string, :terms => :string, :name => :string do
|
9
|
+
validates_acceptance_of :eula, :terms, options
|
10
|
+
end
|
11
|
+
|
12
|
+
validate_acceptance_of(:eula, :terms)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'messages' do
|
16
|
+
before(:each){ @matcher = define_and_validate }
|
17
|
+
|
18
|
+
it 'should contain a description' do
|
19
|
+
@matcher.description.should == 'require eula and terms to be accepted'
|
20
|
+
|
21
|
+
@matcher.accept('true')
|
22
|
+
@matcher.description.should == 'require eula and terms to be accepted with value "true"'
|
23
|
+
|
24
|
+
@matcher.allow_nil
|
25
|
+
@matcher.description.should == 'require eula and terms to be accepted with value "true" and allowing nil values'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set requires_acceptance? message' do
|
29
|
+
@matcher = validate_acceptance_of(:name)
|
30
|
+
@matcher.matches?(@model)
|
31
|
+
@matcher.failure_message.should == 'Expected User to be invalid if name is not accepted'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set accept_is_valid? message' do
|
35
|
+
@matcher.accept('accept_value').matches?(@model)
|
36
|
+
@matcher.failure_message.should == 'Expected User to be valid when eula is accepted with value "accept_value"'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'matchers' do
|
42
|
+
|
43
|
+
describe 'without options' do
|
44
|
+
before(:each){ define_and_validate }
|
45
|
+
|
46
|
+
it { should validate_acceptance_of(:eula) }
|
47
|
+
it { should validate_acceptance_of(:eula, :terms) }
|
48
|
+
it { should_not validate_acceptance_of(:eula, :name) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'with accept as option' do
|
52
|
+
it { should define_and_validate(:accept => 'accept_value').accept('accept_value') }
|
53
|
+
it { should_not define_and_validate(:accept => 'another_value').accept('a_value') }
|
54
|
+
end
|
55
|
+
|
56
|
+
create_message_specs(self)
|
57
|
+
create_optional_boolean_specs(:allow_nil, self)
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'macros' do
|
61
|
+
before(:each){ define_and_validate }
|
62
|
+
|
63
|
+
should_validate_acceptance_of :eula
|
64
|
+
should_validate_acceptance_of :eula, :terms
|
65
|
+
should_not_validate_acceptance_of :eula, :name
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|