remockable 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -20,8 +20,8 @@ the original goal of Remarkable in spirit.
20
20
  ## Matchers
21
21
 
22
22
  Remockable currently includes support for all of the Active Model validation
23
- and allow_mass_assignment_of matchers, and also supports the have_column,
24
- have_index, and have_scope Active Record matchers.
23
+ and allow_mass_assignment_of matchers, and also supports the association,
24
+ have_column, have_index, and have_scope Active Record matchers.
25
25
 
26
26
  More are on the way soon.
27
27
 
@@ -12,9 +12,7 @@ module Remockable
12
12
  end
13
13
 
14
14
  def validate_attributes
15
- @attributes.inject(true) do |result, attribute|
16
- result & yield(validator_for(attribute))
17
- end
15
+ @attributes.all? { |attribute| yield(validator_for(attribute)) }
18
16
  end
19
17
  end
20
18
  end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define(:belong_to) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @association = attributes.first
6
+
7
+ unsupported_options %w(extend)
8
+ valid_options %w(class_name conditions select foreign_key primary_key dependent counter_cache include polymorphic readonly validate autosave touch inverse_of)
9
+
10
+ match do |actual|
11
+ if association = subject.class.reflect_on_association(@association)
12
+ macro_matches = association.macro.should == :belongs_to
13
+ options_match = association.options.slice(*expected.keys) == expected
14
+ macro_matches && options_match
15
+ end
16
+ end
17
+
18
+ failure_message_for_should do |actual|
19
+ "Expected #{subject.class.name} to #{description}"
20
+ end
21
+
22
+ failure_message_for_should_not do |actual|
23
+ "Did not expect #{subject.class.name} to #{description}"
24
+ end
25
+
26
+ description do
27
+ with = " with #{expected.inspect}" if expected.any?
28
+ "belong to #{@association}#{with}"
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define(:have_and_belong_to_many) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @association = attributes.first
6
+
7
+ unsupported_options %w(extend)
8
+ valid_options %w(class_name join_table foreign_key association_foreign_key conditions order uniq finder_sql counter_sql delete_sql insert_sql include group having limit offset select readonly validate autosave)
9
+
10
+ match do |actual|
11
+ if association = subject.class.reflect_on_association(@association)
12
+ macro_matches = association.macro.should == :has_and_belongs_to_many
13
+ options_match = association.options.slice(*expected.keys) == expected
14
+ macro_matches && options_match
15
+ end
16
+ end
17
+
18
+ failure_message_for_should do |actual|
19
+ "Expected #{subject.class.name} to #{description}"
20
+ end
21
+
22
+ failure_message_for_should_not do |actual|
23
+ "Did not expect #{subject.class.name} to #{description}"
24
+ end
25
+
26
+ description do
27
+ with = " with #{expected.inspect}" if expected.any?
28
+ "have and belong to #{@association}#{with}"
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define(:have_many) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @association = attributes.first
6
+
7
+ unsupported_options %w(extend)
8
+ valid_options %w(class_name conditions order foreign_key primary_key dependent finder_sql counter_sql include group having limit offset select as through source source_type uniq readonly validate autosave inverse_of)
9
+
10
+ match do |actual|
11
+ if association = subject.class.reflect_on_association(@association)
12
+ macro_matches = association.macro.should == :has_many
13
+ options_match = association.options.slice(*expected.keys) == expected
14
+ macro_matches && options_match
15
+ end
16
+ end
17
+
18
+ failure_message_for_should do |actual|
19
+ "Expected #{subject.class.name} to #{description}"
20
+ end
21
+
22
+ failure_message_for_should_not do |actual|
23
+ "Did not expect #{subject.class.name} to #{description}"
24
+ end
25
+
26
+ description do
27
+ with = " with #{expected.inspect}" if expected.any?
28
+ "have many #{@association}#{with}"
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define(:have_one) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @association = attributes.first
6
+
7
+ unsupported_options %w(extend)
8
+ valid_options %w(class_name conditions order dependent foreign_key primary_key include as select through source source_type readonly validate autosave inverse_of)
9
+
10
+ match do |actual|
11
+ if association = subject.class.reflect_on_association(@association)
12
+ macro_matches = association.macro.should == :has_one
13
+ options_match = association.options.slice(*expected.keys) == expected
14
+ macro_matches && options_match
15
+ end
16
+ end
17
+
18
+ failure_message_for_should do |actual|
19
+ "Expected #{subject.class.name} to #{description}"
20
+ end
21
+
22
+ failure_message_for_should_not do |actual|
23
+ "Did not expect #{subject.class.name} to #{description}"
24
+ end
25
+
26
+ description do
27
+ with = " with #{expected.inspect}" if expected.any?
28
+ "have a #{@association}#{with}"
29
+ end
30
+ end
@@ -1,4 +1,10 @@
1
1
  require 'remockable/active_record/helpers'
2
+
3
+ require 'remockable/active_record/belong_to'
4
+ require 'remockable/active_record/have_and_belong_to_many'
5
+ require 'remockable/active_record/have_many'
6
+ require 'remockable/active_record/have_one'
7
+
2
8
  require 'remockable/active_record/have_column'
3
9
  require 'remockable/active_record/have_index'
4
10
  require 'remockable/active_record/have_scope'
@@ -1,3 +1,3 @@
1
1
  module Remockable
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: remockable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tyler Hunt
@@ -112,8 +112,12 @@ files:
112
112
  - lib/remockable/active_model/validate_numericality_of.rb
113
113
  - lib/remockable/active_model/validate_presence_of.rb
114
114
  - lib/remockable/active_model.rb
115
+ - lib/remockable/active_record/belong_to.rb
116
+ - lib/remockable/active_record/have_and_belong_to_many.rb
115
117
  - lib/remockable/active_record/have_column.rb
116
118
  - lib/remockable/active_record/have_index.rb
119
+ - lib/remockable/active_record/have_many.rb
120
+ - lib/remockable/active_record/have_one.rb
117
121
  - lib/remockable/active_record/have_scope.rb
118
122
  - lib/remockable/active_record/helpers.rb
119
123
  - lib/remockable/active_record.rb