sample_models 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +4 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +345 -0
  4. data/Rakefile +53 -0
  5. data/VERSION +1 -0
  6. data/init.rb +2 -0
  7. data/install.rb +1 -0
  8. data/lib/sample_models/creation.rb +116 -0
  9. data/lib/sample_models/finder.rb +81 -0
  10. data/lib/sample_models/model.rb +136 -0
  11. data/lib/sample_models/sampler.rb +110 -0
  12. data/lib/sample_models.rb +117 -0
  13. data/sample_models.gemspec +89 -0
  14. data/spec/sample_models_spec.rb +11 -0
  15. data/spec_or_test/database.yml +7 -0
  16. data/spec_or_test/setup.rb +249 -0
  17. data/spec_or_test/specs_or_test_cases.rb +569 -0
  18. data/spec_or_test/vendor/validates_email_format_of/CHANGELOG +11 -0
  19. data/spec_or_test/vendor/validates_email_format_of/MIT-LICENSE +20 -0
  20. data/spec_or_test/vendor/validates_email_format_of/README +28 -0
  21. data/spec_or_test/vendor/validates_email_format_of/TODO +1 -0
  22. data/spec_or_test/vendor/validates_email_format_of/init.rb +1 -0
  23. data/spec_or_test/vendor/validates_email_format_of/lib/validates_email_format_of.rb +41 -0
  24. data/spec_or_test/vendor/validates_email_format_of/rakefile +28 -0
  25. data/spec_or_test/vendor/validates_email_format_of/test/database.yml +3 -0
  26. data/spec_or_test/vendor/validates_email_format_of/test/fixtures/people.yml +3 -0
  27. data/spec_or_test/vendor/validates_email_format_of/test/fixtures/person.rb +3 -0
  28. data/spec_or_test/vendor/validates_email_format_of/test/schema.rb +5 -0
  29. data/spec_or_test/vendor/validates_email_format_of/test/test_helper.rb +35 -0
  30. data/spec_or_test/vendor/validates_email_format_of/test/validates_email_format_of_test.rb +82 -0
  31. data/tasks/sample_models_tasks.rake +4 -0
  32. data/test/test_sample_models.rb +28 -0
  33. data/uninstall.rb +1 -0
  34. data/vendor/ar_query/MIT-LICENSE +20 -0
  35. data/vendor/ar_query/README +0 -0
  36. data/vendor/ar_query/ar_query.gemspec +16 -0
  37. data/vendor/ar_query/init.rb +1 -0
  38. data/vendor/ar_query/install.rb +1 -0
  39. data/vendor/ar_query/lib/ar_query.rb +146 -0
  40. data/vendor/ar_query/spec/ar_query_spec.rb +318 -0
  41. data/vendor/ar_query/tasks/ar_query_tasks.rake +0 -0
  42. data/vendor/ar_query/uninstall.rb +1 -0
  43. metadata +117 -0
@@ -0,0 +1,318 @@
1
+ require File.dirname(__FILE__) + '/../lib/ar_query'
2
+
3
+ describe ARQuery do
4
+ describe '#initialize with no values' do
5
+ before :all do
6
+ ar_query = ARQuery.new
7
+ @hash = ar_query.to_hash
8
+ end
9
+
10
+ it 'should not have conditions' do
11
+ @hash[:conditions].should be_nil
12
+ end
13
+
14
+ it 'should not have joins' do
15
+ @hash[:joins].should be_nil
16
+ end
17
+
18
+ it 'should not let you assign like a hash' do
19
+ lambda {
20
+ @ar_query[:conditions] = "foo = 'bar'"
21
+ }.should raise_error(NoMethodError)
22
+ lambda {
23
+ @ar_query[:joins] = "foo = 'bar'"
24
+ }.should raise_error(NoMethodError)
25
+ end
26
+ end
27
+
28
+ describe '#initialize with values' do
29
+ before :all do
30
+ @ar_query = ARQuery.new(:order => 'id desc', :limit => 25)
31
+ @hash = @ar_query.to_hash
32
+ end
33
+
34
+ it 'should have those values in the hash' do
35
+ @hash[:order].should == 'id desc'
36
+ @hash[:limit].should == 25
37
+ end
38
+
39
+ it 'should not have other values in the hash' do
40
+ @hash[:conditions].should be_nil
41
+ end
42
+ end
43
+
44
+ describe "#condition_sqls <<" do
45
+ before :all do
46
+ @ar_query = ARQuery.new
47
+ @ar_query.condition_sqls << "fname is not null"
48
+ @ar_query.condition_sqls << "lname is not null"
49
+ end
50
+
51
+ it 'should join the conditions with an AND' do
52
+ @ar_query.to_hash[:conditions].should ==
53
+ "(fname is not null) AND (lname is not null)"
54
+ end
55
+
56
+ it "should prevent you from appending nil" do
57
+ lambda { @ar_query.condition_sqls << nil }.should raise_error(
58
+ ArgumentError,
59
+ "Tried appending nil to ARQuery::Condition::SQLs: Only strings are allowed"
60
+ )
61
+ end
62
+
63
+ it "should prevent you from appending a value besides a string" do
64
+ lambda { @ar_query.condition_sqls << 55 }.should raise_error(
65
+ ArgumentError,
66
+ "Tried appending 55 to ARQuery::Condition::SQLs: Only strings are allowed"
67
+ )
68
+ end
69
+ end
70
+
71
+ describe '#condition_sqls << with OR as the boolean join' do
72
+ before :all do
73
+ @ar_query = ARQuery.new
74
+ @ar_query.boolean_join = :or
75
+ @ar_query.condition_sqls << "fname is not null"
76
+ @ar_query.condition_sqls << "lname is not null"
77
+ end
78
+
79
+ it 'should join the conditions with an OR' do
80
+ @ar_query.to_hash[:conditions].should ==
81
+ "(fname is not null) OR (lname is not null)"
82
+ end
83
+ end
84
+
85
+ describe '#conditions hash usage << with OR as the boolean join' do
86
+ before :all do
87
+ @ar_query = ARQuery.new
88
+ @ar_query.boolean_join = :or
89
+ @ar_query.conditions[:fname] = 'John'
90
+ @ar_query.conditions[:lname] = 'Doe'
91
+ end
92
+
93
+ it 'should join the conditions with an OR' do
94
+ @ar_query.to_hash[:conditions].should == [
95
+ "(fname = ?) OR (lname = ?)", 'John', 'Doe'
96
+ ]
97
+ end
98
+ end
99
+
100
+ describe '[:conditions]' do
101
+ describe 'with bind vars' do
102
+ before :all do
103
+ @ar_query = ARQuery.new
104
+ @ar_query.condition_sqls << "fname = ?"
105
+ @ar_query.condition_sqls << "lname = ?"
106
+ end
107
+
108
+ describe 'using appends' do
109
+ before :all do
110
+ @ar_query.condition_bind_vars << 'Francis'
111
+ @ar_query.condition_bind_vars << 'Hwang'
112
+ end
113
+
114
+ it 'should put the bind_vars at the end of the conditions array' do
115
+ @ar_query.to_hash[:conditions].should ==
116
+ [ "(fname = ?) AND (lname = ?)", 'Francis', 'Hwang' ]
117
+ end
118
+ end
119
+
120
+ describe 'using assignment' do
121
+ before :all do
122
+ @ar_query.condition_bind_vars = %w( Francis Hwang )
123
+ end
124
+
125
+ it 'should put the bind_vars at the end of the conditions array' do
126
+ @ar_query.to_hash[:conditions].should ==
127
+ [ "(fname = ?) AND (lname = ?)", 'Francis', 'Hwang' ]
128
+ end
129
+ end
130
+ end
131
+
132
+ describe 'with hash setters' do
133
+ before :all do
134
+ @ar_query = ARQuery.new
135
+ @ar_query.conditions[:fname] = 'John'
136
+ @ar_query.conditions[:lname] = 'Doe'
137
+ end
138
+
139
+ it 'should return conditions as an array with bind vars' do
140
+ @ar_query.to_hash[:conditions].should == [
141
+ "(fname = ?) AND (lname = ?)", 'John', 'Doe'
142
+ ]
143
+ end
144
+ end
145
+
146
+ describe 'with a combination of hash setters and bind vars' do
147
+ before :all do
148
+ @ar_query = ARQuery.new
149
+ @ar_query.conditions[:fname] = 'John'
150
+ @ar_query.condition_sqls << "lname = ?"
151
+ @ar_query.condition_bind_vars << 'Doe'
152
+ end
153
+
154
+ it 'should return conditions as an array with bind vars' do
155
+ @ar_query.to_hash[:conditions].should == [
156
+ "(fname = ?) AND (lname = ?)", 'John', 'Doe'
157
+ ]
158
+ end
159
+ end
160
+ end
161
+
162
+ describe 'with a nested condition' do
163
+ before :all do
164
+ @ar_query = ARQuery.new
165
+ @ar_query.condition_sqls << "fname = ?"
166
+ @ar_query.condition_bind_vars << 'Francis'
167
+ @ar_query.add_condition do |cond|
168
+ cond.boolean_join = :or
169
+ cond.sqls << 'lname = ?'
170
+ cond.sqls << 'lname = ?'
171
+ cond.bind_vars << 'Hwang'
172
+ cond.bind_vars << 'Bacon'
173
+ cond.ar_query.should == @ar_query
174
+ end
175
+ end
176
+
177
+ it 'should generate nested conditions in SQL' do
178
+ @ar_query.to_hash[:conditions].should == [
179
+ "(fname = ?) AND ((lname = ?) OR (lname = ?))",
180
+ 'Francis', 'Hwang', 'Bacon'
181
+ ]
182
+ end
183
+ end
184
+
185
+ describe 'with a nested condition using hash setters' do
186
+ before :all do
187
+ @ar_query = ARQuery.new
188
+ @ar_query.condition_sqls << "fname = ?"
189
+ @ar_query.condition_bind_vars << 'Francis'
190
+ @ar_query.add_condition do |cond|
191
+ cond.boolean_join = :or
192
+ cond[:lname] = 'Hwang'
193
+ cond[:city] = 'Brooklyn'
194
+ cond.ar_query.should == @ar_query
195
+ end
196
+ end
197
+
198
+ it 'should generate nested conditions in SQL' do
199
+ @ar_query.to_hash[:conditions].should == [
200
+ "(fname = ?) AND ((lname = ?) OR (city = ?))",
201
+ 'Francis', 'Hwang', 'Brooklyn'
202
+ ]
203
+ end
204
+ end
205
+
206
+ describe "when using the nested condition syntax even though the query isn't nested" do
207
+ before :all do
208
+ @ar_query = ARQuery.new
209
+ @ar_query.add_condition do |cond|
210
+ cond.boolean_join = :or
211
+ cond.sqls << "fname = ?"
212
+ cond.bind_vars << 'Chunky'
213
+ end
214
+ end
215
+
216
+ it 'should generate the non-nested condition in SQL' do
217
+ @ar_query.to_hash[:conditions].should == ["(fname = ?)", 'Chunky']
218
+ end
219
+ end
220
+
221
+ describe 'when nesting the nested condition unnecessarily' do
222
+ before :all do
223
+ @ar_query = ARQuery.new
224
+ @ar_query.add_condition do |cond|
225
+ cond.add_condition do |subcond|
226
+ subcond.boolean_join = :or
227
+ subcond.sqls << "fname = ?"
228
+ subcond.bind_vars << 'Chunky'
229
+ end
230
+ end
231
+ end
232
+
233
+ it 'should generate the non-nested condition in SQL' do
234
+ @ar_query.to_hash[:conditions].should == ["(fname = ?)", 'Chunky']
235
+ end
236
+ end
237
+
238
+ describe 'when calling an empty #add_condition after already adding to condition_sqls' do
239
+ before :all do
240
+ @ar_query = ARQuery.new
241
+ @ar_query.condition_sqls << "published = true"
242
+ @ar_query.add_condition do |cond|
243
+ end
244
+ end
245
+
246
+ it 'should not append anything to the condition' do
247
+ @ar_query.to_hash[:conditions].should == '(published = true)'
248
+ end
249
+ end
250
+
251
+ describe '#joins <<' do
252
+ describe 'when there are no joins to start' do
253
+ before :all do
254
+ @ar_query = ARQuery.new
255
+ @ar_query.joins << :user
256
+ end
257
+
258
+ it 'should result in an array of 1 join' do
259
+ @ar_query.to_hash[:joins].should == [:user]
260
+ end
261
+ end
262
+
263
+ describe 'when it was initialized with one join' do
264
+ before :all do
265
+ @ar_query = ARQuery.new :joins => :user
266
+ @ar_query.joins << :tags
267
+ end
268
+
269
+ it 'should result in an array of 2 joins' do
270
+ @ar_query.to_hash[:joins].should == [:user, :tags]
271
+ end
272
+ end
273
+
274
+ describe 'when there are already two joins' do
275
+ before :all do
276
+ @ar_query = ARQuery.new :joins => [:user, :tags]
277
+ @ar_query.joins << :images
278
+ end
279
+
280
+ it 'should result in 3 joins' do
281
+ @ar_query.to_hash[:joins].should == [:user, :tags, :images]
282
+ end
283
+ end
284
+
285
+ describe 'when a duplicate join is being appended' do
286
+ before :all do
287
+ @ar_query = ARQuery.new :joins => [:user, :tags]
288
+ @ar_query.joins << :user
289
+ end
290
+
291
+ it 'should not keep the array of joins unique' do
292
+ @ar_query.to_hash[:joins].should == [:user, :tags]
293
+ end
294
+ end
295
+
296
+ describe 'when the same association has already been :included' do
297
+ before :all do
298
+ @ar_query = ARQuery.new :include => 'user'
299
+ @ar_query.joins << :user
300
+ end
301
+
302
+ it 'should not include the association in the join' do
303
+ @ar_query.to_hash[:joins].should be_nil
304
+ end
305
+ end
306
+ end
307
+
308
+ describe '#total_entries =' do
309
+ before :all do
310
+ @ar_query = ARQuery.new
311
+ @ar_query.total_entries = 25
312
+ end
313
+
314
+ it 'should set [:total_entries]' do
315
+ @ar_query.to_hash[:total_entries].should == 25
316
+ end
317
+ end
318
+ end
File without changes
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sample_models
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - Francis Hwang
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-06 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+
24
+ A library for making it extremely fast for Rails developers to set up and save ActiveRecord instances when writing test cases. It aims to:
25
+
26
+ * meet all your validations automatically
27
+ * only make you specify the attributes you care about
28
+ * give you a rich set of features so you can specify associated values as concisely as possible
29
+ * do this with as little configuration as possible
30
+
31
+ email: francis.hwang@profitably.com
32
+ executables: []
33
+
34
+ extensions: []
35
+
36
+ extra_rdoc_files:
37
+ - README.markdown
38
+ files:
39
+ - .gitignore
40
+ - MIT-LICENSE
41
+ - README.markdown
42
+ - Rakefile
43
+ - VERSION
44
+ - init.rb
45
+ - install.rb
46
+ - lib/sample_models.rb
47
+ - lib/sample_models/creation.rb
48
+ - lib/sample_models/finder.rb
49
+ - lib/sample_models/model.rb
50
+ - lib/sample_models/sampler.rb
51
+ - sample_models.gemspec
52
+ - spec/sample_models_spec.rb
53
+ - spec_or_test/database.yml
54
+ - spec_or_test/setup.rb
55
+ - spec_or_test/specs_or_test_cases.rb
56
+ - spec_or_test/vendor/validates_email_format_of/CHANGELOG
57
+ - spec_or_test/vendor/validates_email_format_of/MIT-LICENSE
58
+ - spec_or_test/vendor/validates_email_format_of/README
59
+ - spec_or_test/vendor/validates_email_format_of/TODO
60
+ - spec_or_test/vendor/validates_email_format_of/init.rb
61
+ - spec_or_test/vendor/validates_email_format_of/lib/validates_email_format_of.rb
62
+ - spec_or_test/vendor/validates_email_format_of/rakefile
63
+ - spec_or_test/vendor/validates_email_format_of/test/database.yml
64
+ - spec_or_test/vendor/validates_email_format_of/test/fixtures/people.yml
65
+ - spec_or_test/vendor/validates_email_format_of/test/fixtures/person.rb
66
+ - spec_or_test/vendor/validates_email_format_of/test/schema.rb
67
+ - spec_or_test/vendor/validates_email_format_of/test/test_helper.rb
68
+ - spec_or_test/vendor/validates_email_format_of/test/validates_email_format_of_test.rb
69
+ - tasks/sample_models_tasks.rake
70
+ - test/test_sample_models.rb
71
+ - uninstall.rb
72
+ - vendor/ar_query/MIT-LICENSE
73
+ - vendor/ar_query/README
74
+ - vendor/ar_query/ar_query.gemspec
75
+ - vendor/ar_query/init.rb
76
+ - vendor/ar_query/install.rb
77
+ - vendor/ar_query/lib/ar_query.rb
78
+ - vendor/ar_query/spec/ar_query_spec.rb
79
+ - vendor/ar_query/tasks/ar_query_tasks.rake
80
+ - vendor/ar_query/uninstall.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/fhwang/sample_models
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: A library for making it extremely fast for Rails developers to set up and save ActiveRecord instances when writing test cases
115
+ test_files:
116
+ - spec/sample_models_spec.rb
117
+ - test/test_sample_models.rb