factory_boy 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,18 +1,23 @@
1
1
  == Overview
2
+
2
3
  Factory Boy aims to avoid slow unit tests due to usage of create/find fixtures in database, with factory_girl for example.
4
+
3
5
  Factory Boy can be used as factory_girl except that factories are not created in database.
4
- ActiveRecord::Base finders method is stubbed to return fixtures (plants) you have instanciate.
6
+
7
+ ActiveRecord::Base finders are stubbed to return fixtures (plants) you have instanciated.
5
8
 
6
9
  Now, Factory Boy 2 handle stub of Active Record (3+) queries.
7
10
  This means, the fixtures(plants) created with factory boy are retrieved via a AR queries(and only with AR new queries) of your models.
11
+
8
12
  It does not pretend to stub 100% of all queries, but the coverage can be estimated at about 80%-90% of useful queries.
9
13
 
10
14
 
11
- Active Record is stubbed only when at least one Plant is created in a test.
12
- After each test everything is unstubbed.
15
+ <b>Active Record is stubbed only when at least one Plant is created in a test.</b>
16
+
17
+ <b>After each test everything is unstubbed.</b>
13
18
  That means, if you have a case where a particular(complex) query is executed but not right stubbed with factory boy you can test using fixtures in databases(with factory girl or just model.create ..), skipping factory boy process.
14
19
 
15
- Tested with Active Record 3.0.1
20
+ Tested with Active Record > 3.0.1
16
21
  Tests are suppose to use ActiveSupport::TestCase
17
22
 
18
23
  See some examples below.
@@ -28,6 +33,8 @@ You should see unit tests to inspect tested stubbed queries!
28
33
  - order (with only one order clause)
29
34
  - ranges (ie where(:age => (20..30)))
30
35
  - IS NULL and IS NOT NULL sql predicates
36
+ - dynamic finders (ie find_by_name_and_age(...)
37
+ - scopes
31
38
 
32
39
  The better way to see queries handled is to see all unit tests.
33
40
 
@@ -36,6 +43,11 @@ The better way to see queries handled is to see all unit tests.
36
43
  - Queries with explicit sql string(find_by_sql("..."))
37
44
  - #order with more than one order clause (ie .order(name asc, age desc))
38
45
  - IS and IS NOT with other operand than NULL
46
+ - having - group clauses methods
47
+ - select clause method
48
+ - lock
49
+ - readonly
50
+ - from
39
51
 
40
52
  == Ids
41
53
 
@@ -45,7 +57,7 @@ Each plant fixture has now an (unique) id.
45
57
 
46
58
  Define your Plants (~ Factories if factory_girl) in test/plants.rb
47
59
 
48
- Example :
60
+ <b>Examples :</b>
49
61
 
50
62
  Plant.define :address do |address|
51
63
  address.number = 12
@@ -58,7 +70,6 @@ Example :
58
70
  user.addresses = [Plant(:address)]
59
71
  end
60
72
 
61
-
62
73
 
63
74
  Get it with :
64
75
 
@@ -148,7 +159,11 @@ As with factory_girl you are able to use sequences, like that :
148
159
  == In Development
149
160
 
150
161
  - Stubs aggregations methods in queries(sum, count ...)
151
-
162
+ - Having - group clauses methods
163
+ - Select clause method
164
+ - Case when primary key is not id
165
+ - Handle table name modified via table_name method
166
+ - Handle foreign key specified name (ie foreign_key => ) in association declaration
152
167
 
153
168
  == Install
154
169
 
@@ -156,9 +171,9 @@ As with factory_girl you are able to use sequences, like that :
156
171
 
157
172
 
158
173
  == Change Log
174
+ * add require 'active_support/test_case' To fix constant not found Test (setup.rb) when ran as gem under rails 3 app
175
+ * FIX : When : statements incompatibility with ruby 1.9.2
176
+ == Note
159
177
 
178
+ If you use it, thanks to report feedbacks here, as issue or by git mail box, it will help me to enhance it. <b>Thanks!</b>
160
179
 
161
-
162
- == Issues
163
-
164
- <b>Report Bugs here , on github</b>
data/lib/blank_slate.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class BlankSlate
2
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
2
+ instance_methods.each { |m| undef_method m unless (m =~ /^__/ ) || (m =~/object_id/)}
3
3
  end
data/lib/selector.rb CHANGED
@@ -20,7 +20,7 @@ module Plant
20
20
 
21
21
  copy.gsub!(/\s<>\s/, " != ")
22
22
  copy.gsub!('"','')
23
-
23
+
24
24
  copy.match(/(\sLIKE\s*)'/i)
25
25
  copy.gsub!($1,'.match ') if $1
26
26
 
@@ -92,7 +92,7 @@ module Plant
92
92
 
93
93
  def type_cast operand, value
94
94
  case value
95
- when TrueClass, FalseClass : (operand == 't' || operand == '1')
95
+ when TrueClass, FalseClass then (operand == 't' || operand == '1')
96
96
  else operand
97
97
  end
98
98
  end
@@ -144,10 +144,10 @@ module Plant
144
144
 
145
145
  def select
146
146
  condition = Condition.new(@wheres, @klass)
147
-
147
+
148
148
  Plant::Stubber.stubs_associations_collections
149
149
  Plant::Stubber.stubs_attribute_methods
150
- objects = @plants.select {|object| @binding = binding(); eval("#{condition.to_ruby}")}
150
+ objects = @plants.select {|object| @binding = binding();eval("#{condition.to_ruby}")}
151
151
  Plant::Stubber.unstubs_associations_collections
152
152
  Plant::Stubber.unstubs_attribute_methods
153
153
 
data/lib/stubber.rb CHANGED
@@ -61,9 +61,9 @@ module Plant
61
61
  def self.stubs_array
62
62
  redefine(Array, :method_missing) do |method, *args, &block|
63
63
  case method
64
- when :order : Plant::Query.order(self, *args)
65
- when :limit : Plant::Query.limit(self, *args)
66
- when :offset : Plant::Query.offset(self, *args)
64
+ when :order then Plant::Query.order(self, *args)
65
+ when :limit then Plant::Query.limit(self, *args)
66
+ when :offset then Plant::Query.offset(self, *args)
67
67
  end
68
68
  end
69
69
  end
data/test/help_test.rb CHANGED
@@ -2,7 +2,7 @@ Object.const_set("RAILS_ROOT", File.join(File.dirname(__FILE__), '../') )
2
2
 
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
- gem 'activerecord', version='3.0.1'
5
+ gem 'activerecord', '>= 3.0.1'
6
6
  require 'active_record'
7
7
 
8
8
  require 'app/models/address'
@@ -33,4 +33,5 @@ class TestBasicQueries < ActiveSupport::TestCase
33
33
  assert_equal [user_1, user_2], User.find(user_1.id, user_2.id)
34
34
  end
35
35
 
36
+
36
37
  end
@@ -12,7 +12,7 @@ class TestQueriesOnHasManyAssociation < ActiveSupport::TestCase
12
12
  end
13
13
 
14
14
  def test_queries_with_conditions_on_has_many_association_with_non_equality_operator
15
- addresses = [Plant(:address, :street => '21 Jump Street'), Plant(:address, :street => 'Rue des Lilas')]
15
+ addresses = [Plant(:address, :street => '21 Jump Street')]
16
16
  joe = Plant(:user, :name => 'Joe', :age => 30, :addresses => addresses)
17
17
 
18
18
  assert_equal([], User.where("addresses.street != '21 Jump Street'").joins(:addresses))
@@ -0,0 +1,12 @@
1
+ require 'help_test'
2
+
3
+ class TestQueriesWithDynamicFinders< ActiveSupport::TestCase
4
+
5
+ def test_queries_with_dynamic_finder_on_attributes
6
+ user = Plant(:user, :name => 'toto', :age => 30)
7
+
8
+ assert_equal user, User.find_by_name('toto')
9
+ assert_equal user, User.find_by_name_and_age('toto', 30)
10
+ end
11
+
12
+ end
@@ -3,7 +3,7 @@ require 'help_test'
3
3
  class TestSelectorCondition < ActiveSupport::TestCase
4
4
 
5
5
  def test_should_transform_sql_conditions_to_ruby_select_conditions_with_one_where
6
- condition = Plant::Selector::Condition.new("(users.name = 'Joe')", User)
6
+ condition = Plant::Selector::Condition.new(["(users.name = 'Joe')"], User)
7
7
 
8
8
  assert_equal "(users.name == 'Joe')", condition.to_ruby
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_boy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philippe Cantin
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-23 00:00:00 +01:00
18
+ date: 2011-04-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: " Factory Girl with database accesses stubbed.\n The versions 2+ only work with Rails 3 (AR 3+) for stubbing queries.\n Now handle Rails 3 (only Rails 3) queries stubbing,\n Transform rail3 queries into ruby select on Plants created with factory boy.\n Example\n user = Plant(:user => 'toto', :addresses => [Plant(:address, :street => 'here')])\n User.where(:name => 'toto').where('addresses.street = 'here').joins(:addresses) will be stubbed into\n a select ruby on plants and return here, user.\n See more on github and in unit tests.\n"
22
+ description: " Factory Girl with database accesses stubbed.\n The versions 2+ only work with Rails 3 (AR 3+) for stubbing queries.\n Now handle Rails 3 (only Rails 3) queries stubbing,\n Transform rail3 queries into ruby select on Plants created with factory boy.\n Example\n user = Plant(:user => 'toto', :addresses => [Plant(:address, :street => 'here')])\n User.where(:name => 'toto').where('addresses.street = 'here').joins(:addresses) will be stubbed into\n a select ruby on plants and return here, user.\n See more on github and in unit tests.\n Compatible ruby 1.9.2.\n"
23
23
  email:
24
24
  executables: []
25
25
 
@@ -56,6 +56,7 @@ files:
56
56
  - test/test_queries_on_has_many_association.rb
57
57
  - test/test_queries_on_has_one_association.rb
58
58
  - test/test_queries_on_model_attributes.rb
59
+ - test/test_queries_with_dynamic_finders.rb
59
60
  - test/test_queries_with_like.rb
60
61
  - test/test_queries_with_limit.rb
61
62
  - test/test_queries_with_named_scope.rb
@@ -117,6 +118,7 @@ test_files:
117
118
  - test/test_queries_on_has_many_association.rb
118
119
  - test/test_queries_on_has_one_association.rb
119
120
  - test/test_queries_on_model_attributes.rb
121
+ - test/test_queries_with_dynamic_finders.rb
120
122
  - test/test_queries_with_like.rb
121
123
  - test/test_queries_with_limit.rb
122
124
  - test/test_queries_with_named_scope.rb