page_record 0.4.0 → 0.5.0

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.
Files changed (41) hide show
  1. data/.rubocop.yml +13 -0
  2. data/CHANGES.md +5 -0
  3. data/Gemfile.lock +46 -14
  4. data/Guardfile +24 -0
  5. data/README.md +27 -1
  6. data/bin/autospec +16 -0
  7. data/bin/guard +16 -0
  8. data/bin/rake +16 -0
  9. data/bin/rspec +16 -0
  10. data/lib/page_record/attribute_accessors.rb +57 -54
  11. data/lib/page_record/base.rb +27 -22
  12. data/lib/page_record/class_actions.rb +47 -50
  13. data/lib/page_record/class_methods.rb +252 -261
  14. data/lib/page_record/errors.rb +81 -82
  15. data/lib/page_record/finders.rb +129 -131
  16. data/lib/page_record/form_builder.rb +4 -4
  17. data/lib/page_record/formtastic.rb +20 -9
  18. data/lib/page_record/helpers.rb +192 -131
  19. data/lib/page_record/inspector.rb +36 -0
  20. data/lib/page_record/instance_actions.rb +44 -46
  21. data/lib/page_record/rspec.rb +1 -1
  22. data/lib/page_record/validation.rb +46 -0
  23. data/lib/page_record/version.rb +1 -1
  24. data/lib/page_record.rb +13 -15
  25. data/page_record.gemspec +4 -1
  26. data/spec/.rubocop.yml +4 -0
  27. data/spec/helpers_spec.rb +109 -100
  28. data/spec/inspector_spec.rb +70 -0
  29. data/spec/page_record_spec.rb +357 -388
  30. data/spec/spec_helper.rb +1 -3
  31. data/spec/support/shared_contexts.rb +24 -2
  32. data/spec/support/shared_examples.rb +41 -45
  33. data/spec/support/team.rb +4 -4
  34. data/spec/support/test_app.rb +10 -13
  35. data/spec/support/views/page-with-1-error.erb +5 -0
  36. data/spec/support/views/page-with-2-errors-on-different-attributes.erb +9 -0
  37. data/spec/support/views/page-with-2-errors-on-same-attribute.erb +6 -0
  38. data/spec/support/views/page-without-errors.erb +4 -0
  39. data/spec/validation_spec.rb +142 -0
  40. data/tmp/rspec_guard_result +1 -0
  41. metadata +80 -5
@@ -2,561 +2,530 @@ require_relative './spec_helper'
2
2
 
3
3
  describe PageRecord::Base do
4
4
 
5
- include_context "page with single table with 3 records" # Default context
5
+ include_context "page with single table with 3 records" # Default context
6
6
 
7
- before do
8
- class TeamPage < PageRecord::Base; end
9
- PageRecord::Base.page page
10
- end
7
+ before do
8
+ class TeamPage < PageRecord::Base; end
9
+ PageRecord::Base.page page
10
+ end
11
11
 
12
12
  describe ".type" do
13
13
 
14
- before do
15
- class CamelCase
16
- def self.attribute_names
17
- [ 'id' , 'name', 'points', 'ranking', 'goals']
18
- end
19
- end
20
- end
21
-
22
- after do
23
- Object.send(:remove_const, :CamelCasePage)
24
- end
14
+ before do
15
+ class CamelCase
16
+ def self.attribute_names
17
+ %w(id name points ranking goals)
18
+ end
19
+ end
20
+ end
25
21
 
22
+ after do
23
+ Object.send(:remove_const, :CamelCasePage)
24
+ end
26
25
 
27
- context "no type given" do
26
+ context "no type given" do
28
27
 
29
- before do
30
- class CamelCasePage < PageRecord::Base; end
31
- end
28
+ before do
29
+ class CamelCasePage < PageRecord::Base; end
30
+ end
32
31
 
33
- it "returns the internal type of the class " do
34
- expect( CamelCasePage.type).to eq "camel_case"
35
- end
36
- end
32
+ it "returns the internal type of the class " do
33
+ expect(CamelCasePage.type).to eq "camel_case"
34
+ end
35
+ end
37
36
 
38
- context "a type given" do
37
+ context "a type given" do
39
38
 
40
- before do
41
- class CamelCasePage < PageRecord::Base
42
- type :team
43
- end
44
- end
45
-
46
- it "sets the internal type of the class" do
47
- expect( CamelCasePage.type).to eq :team
48
- end
49
- end
39
+ before do
40
+ class CamelCasePage < PageRecord::Base
41
+ type :team
42
+ end
43
+ end
50
44
 
45
+ it "sets the internal type of the class" do
46
+ expect(CamelCasePage.type).to eq :team
47
+ end
48
+ end
51
49
 
52
50
  end
53
51
 
54
-
55
52
  describe ".attributes" do
56
53
 
57
- after do
58
- Object.send(:remove_const, :TeamPage)
59
- end
54
+ after do
55
+ Object.send(:remove_const, :TeamPage)
56
+ end
60
57
 
61
- context "no parameter given" do
58
+ context "no parameter given" do
62
59
 
63
- it "returns all current recognised attributes" do
64
- expect(TeamPage.attributes).to eq ['name', 'points', 'ranking', 'goals']
65
- end
66
- end
60
+ it "returns all current recognised attributes" do
61
+ expect(TeamPage.attributes).to eq %w(name points ranking goals)
62
+ end
63
+ end
67
64
 
68
- context "parameter given" do
65
+ context "parameter given" do
69
66
 
70
- subject { TeamPage}
67
+ subject { TeamPage }
71
68
 
72
- before do
73
- class TeamPage < PageRecord::Base
74
- attributes ['country', 'stadium']
75
- end
76
- end
69
+ before do
70
+ class TeamPage < PageRecord::Base
71
+ attributes %w(country stadium)
72
+ end
73
+ end
77
74
 
78
- it "clears all old class methods" do
79
- expect(subject).not_to respond_to(:find_by_name)
80
- expect(subject).not_to respond_to(:find_by_ranking)
81
- end
75
+ it "clears all old class methods" do
76
+ expect(subject).not_to respond_to(:find_by_name)
77
+ expect(subject).not_to respond_to(:find_by_ranking)
78
+ end
82
79
 
83
- it "adds new class methods to class " do
84
- expect(subject).to respond_to(:find_by_country)
85
- expect(subject).to respond_to(:find_by_stadium)
86
- end
80
+ it "adds new class methods to class " do
81
+ expect(subject).to respond_to(:find_by_country)
82
+ expect(subject).to respond_to(:find_by_stadium)
83
+ end
87
84
 
88
- it "clears all old instance methods" do
89
- expect(subject.new(1)).not_to respond_to(:name)
90
- expect(subject.new(1)).not_to respond_to(:ranking)
91
- end
85
+ it "clears all old instance methods" do
86
+ expect(subject.new(1)).not_to respond_to(:name)
87
+ expect(subject.new(1)).not_to respond_to(:ranking)
88
+ end
92
89
 
93
- it "adds new class methods to class " do
94
- expect(subject.new(1)).to respond_to(:country)
95
- expect(subject.new(1)).to respond_to(:stadium)
96
- end
90
+ it "adds new class methods to class " do
91
+ expect(subject.new(1)).to respond_to(:country)
92
+ expect(subject.new(1)).to respond_to(:stadium)
93
+ end
97
94
 
98
- it "returns all current recognised attributes" do
99
- expect(TeamPage.attributes).to eq ['country', 'stadium']
100
- end
101
- end
95
+ it "returns all current recognised attributes" do
96
+ expect(TeamPage.attributes).to eq %w(country stadium)
97
+ end
98
+ end
102
99
 
103
100
  end
104
101
 
105
-
106
102
  describe ".add_attributes" do
107
- before do
108
- class TeamPage < PageRecord::Base
109
- add_attributes ['country', 'stadium']
110
- end
111
- end
112
-
113
- after do
114
- Object.send(:remove_const, :TeamPage)
115
- end
116
-
117
- subject { TeamPage}
118
-
119
-
120
- it "keeps all old class methods" do
121
- expect(subject).to respond_to(:find_by_name)
122
- expect(subject).to respond_to(:find_by_ranking)
123
- end
124
-
125
- it "adds new class methods to class " do
126
- expect(subject).to respond_to(:find_by_country)
127
- expect(subject).to respond_to(:find_by_stadium)
128
- end
129
-
130
- it "keeps all old instance methods" do
131
- expect(subject.new(1)).to respond_to(:name)
132
- expect(subject.new(1)).to respond_to(:ranking)
133
- end
134
-
135
- it "adds new class methods to class " do
136
- expect(subject.new(1)).to respond_to(:country)
137
- expect(subject.new(1)).to respond_to(:stadium)
138
- end
139
-
140
- it "returns all current attributes" do
141
- expect(subject.add_attributes ['more']).to eq ['name', 'points', 'ranking', 'goals', 'country', 'stadium', 'more' ]
142
- end
143
-
103
+ before do
104
+ class TeamPage < PageRecord::Base
105
+ add_attributes %w(country stadium)
106
+ end
107
+ end
108
+
109
+ after do
110
+ Object.send(:remove_const, :TeamPage)
111
+ end
112
+
113
+ subject { TeamPage }
114
+
115
+ it "keeps all old class methods" do
116
+ expect(subject).to respond_to(:find_by_name)
117
+ expect(subject).to respond_to(:find_by_ranking)
118
+ end
119
+
120
+ it "adds new class methods to class " do
121
+ expect(subject).to respond_to(:find_by_country)
122
+ expect(subject).to respond_to(:find_by_stadium)
123
+ end
124
+
125
+ it "keeps all old instance methods" do
126
+ expect(subject.new(1)).to respond_to(:name)
127
+ expect(subject.new(1)).to respond_to(:ranking)
128
+ end
129
+
130
+ it "adds new class methods to class " do
131
+ expect(subject.new(1)).to respond_to(:country)
132
+ expect(subject.new(1)).to respond_to(:stadium)
133
+ end
134
+
135
+ it "returns all current attributes" do
136
+ expect(subject.add_attributes ['more']).to eq %w(name points ranking goals country stadium more)
137
+ end
144
138
 
145
139
  end
146
140
 
147
-
148
-
149
-
150
141
  describe ".page" do
151
142
 
152
- context "with a parameter" do
153
- let(:test_page) { Object.new}
154
- subject {PageRecord::Base.page test_page }
155
-
156
- it "sets the page when called on PageRecord::Base" do
157
- expect{subject}.to change{PageRecord::Base.page}.to(test_page)
158
- end
143
+ context "with a parameter" do
144
+ let(:test_page) { Object.new }
145
+ subject { PageRecord::Base.page test_page }
159
146
 
160
- it "sets the page when called on subclass" do
161
- expect{TeamPage.page test_page}.to change{PageRecord::Base.page}.to(test_page)
162
- end
163
- end
147
+ it "sets the page when called on PageRecord::Base" do
148
+ expect { subject }.to change { PageRecord::Base.page }.to(test_page)
149
+ end
164
150
 
165
- context "without a parameter" do
166
- it "gets the page on PageRecord::Base" do
167
- expect(PageRecord::Base.page).to eq page
168
- end
151
+ it "sets the page when called on subclass" do
152
+ expect { TeamPage.page test_page }.to change { PageRecord::Base.page }.to(test_page)
153
+ end
154
+ end
169
155
 
170
- it "gets the page on subclass" do
171
- expect(TeamPage.page).to eq page
172
- end
173
- end
156
+ context "without a parameter" do
157
+ it "gets the page on PageRecord::Base" do
158
+ expect(PageRecord::Base.page).to eq page
159
+ end
174
160
 
161
+ it "gets the page on subclass" do
162
+ expect(TeamPage.page).to eq page
163
+ end
164
+ end
175
165
 
176
166
  end
177
167
 
178
-
179
168
  describe ".host_class" do
180
169
 
181
- before do
182
- class FunnyRecord < PageRecord::Base
183
- host_class Team
184
- end
185
- end
186
-
187
- context "with a parameter" do
170
+ before do
171
+ class FunnyRecord < PageRecord::Base
172
+ host_class Team
173
+ end
174
+ end
188
175
 
176
+ context "with a parameter" do
189
177
 
190
- # TODO refactor test
191
- subject {FunnyRecord.new(1) }
178
+ # TODO: refactor test
179
+ subject { FunnyRecord.new(1) }
192
180
 
193
- it "sets the host class" do
194
- expect(FunnyRecord.host_class).to eq Team
195
- end
181
+ it "sets the host class" do
182
+ expect(FunnyRecord.host_class).to eq Team
183
+ end
196
184
 
197
- it "responds to all attributes of host_class" do
198
- attributes = [ 'name', 'points', 'ranking', 'goals']
199
- attributes.each do |attribute|
200
- expect(subject).to respond_to(attribute)
201
- end
202
- end
185
+ it "responds to all attributes of host_class" do
186
+ attributes = %w(name points ranking goals)
187
+ attributes.each do |attribute|
188
+ expect(subject).to respond_to(attribute)
189
+ end
190
+ end
203
191
 
204
- end
192
+ end
205
193
 
206
- context "without a parameter" do
194
+ context "without a parameter" do
207
195
 
208
- it "returns the host_class" do
209
- expect(FunnyRecord.host_class).to eq Team
210
- end
196
+ it "returns the host_class" do
197
+ expect(FunnyRecord.host_class).to eq Team
198
+ end
211
199
 
212
- end
200
+ end
213
201
 
214
202
  end
215
203
 
204
+ describe ".all" do
216
205
 
206
+ subject { TeamPage.all(selector, filter) }
217
207
 
218
- describe ".all" do
219
-
220
-
221
- subject {TeamPage.all( selector, filter) }
222
-
223
- context "one set of records available on the page" do
224
- let(:selector) {""}
225
- let(:filter) {""}
226
-
227
- it_behaves_like "valid call of .all"
228
-
229
- context "with a filter" do
230
- let(:filter) {".champions_league"}
231
-
232
- it "returns only the elements that contain the filter css" do
233
- expect( subject.map {|c| c.name}).not_to include('Feijenoord')
234
- expect( subject.map {|c| c.name}).to include(*['Ajax', 'PSV'])
235
- end
236
- end
237
-
208
+ context "one set of records available on the page" do
209
+ let(:selector) { "" }
210
+ let(:filter) { "" }
238
211
 
239
- end
212
+ it_behaves_like "valid call of .all"
240
213
 
241
- context "No records available on the page" do
214
+ context "with a filter" do
215
+ let(:filter) { ".champions_league" }
242
216
 
243
- include_context "page without records"
244
- let(:selector) {""}
245
- let(:filter) {""}
217
+ it "returns only the elements that contain the filter css" do
218
+ expect(subject.map { |c| c.name }).not_to include('Feijenoord')
219
+ expect(subject.map { |c| c.name }).to include(*%w(Ajax PSV))
220
+ end
221
+ end
246
222
 
223
+ end
247
224
 
248
- it "returns an empty Array" do
249
- expect(subject).to eq []
250
- end
225
+ context "No records available on the page" do
251
226
 
252
- end
227
+ include_context "page without records"
228
+ let(:selector) { "" }
229
+ let(:filter) { "" }
253
230
 
254
- context "multiple sets of records avialable on the page" do
255
- include_context "page with two tables with 3 records"
231
+ it "returns an empty Array" do
232
+ expect(subject).to eq []
233
+ end
256
234
 
257
- context "without selector" do
258
- let(:selector) {""}
259
- let(:filter) {""}
235
+ end
260
236
 
237
+ context "multiple sets of records avialable on the page" do
238
+ include_context "page with two tables with 3 records"
261
239
 
262
- it "raises error PageRecord::MultipleRecords" do
263
- expect{subject}.to raise_error(PageRecord::MultipleRecords)
264
- end
240
+ context "without selector" do
241
+ let(:selector) { "" }
242
+ let(:filter) { "" }
265
243
 
266
- end
244
+ it "raises error PageRecord::MultipleRecords" do
245
+ expect { subject }.to raise_error(PageRecord::MultipleRecords)
246
+ end
267
247
 
268
- it_behaves_like "handles invalid selectors"
248
+ end
269
249
 
270
- context "with a correct selector" do
250
+ it_behaves_like "handles invalid selectors"
271
251
 
272
- let(:selector) {"#first-table"}
273
- let(:filter) {""}
252
+ context "with a correct selector" do
274
253
 
275
- it_behaves_like "valid call of .all"
254
+ let(:selector) { "#first-table" }
255
+ let(:filter) { "" }
276
256
 
277
- end
257
+ it_behaves_like "valid call of .all"
278
258
 
279
- end
259
+ end
280
260
 
281
- end
261
+ end
282
262
 
263
+ end
283
264
 
284
- describe "inherited class" do
285
-
286
- subject {TeamPage.new(1) }
287
-
288
- it "responds to all attributes of corresponding AR Class" do
289
- Team.attribute_names.each do |attribute|
290
- expect(subject).to respond_to(attribute)
291
- end
292
- end
293
-
294
- it "responds <attribute>? of corresponding AR Class" do
295
- Team.attribute_names.each do |attribute|
296
- expect(subject).to respond_to("#{attribute}?")
297
- end
298
- end
299
-
300
- #
301
- # Checks a bug
302
- it "leaves attribute_names of host class intact"
303
-
304
-
305
- end
306
-
307
- describe "action method on class" do
308
- pending
309
- end
310
-
311
-
312
- describe ".find" do
313
-
314
- subject {TeamPage.find(record_number, selector, filter) }
315
- let(:selector) { ""}
316
- let(:filter) {""}
317
-
318
- context "find without an id" do
319
- pending
320
- end
321
-
322
- context "one found on the page" do
323
-
324
- let(:record_number) { 1}
265
+ describe "inherited class" do
325
266
 
326
- it_behaves_like "a valid call of .find"
267
+ subject { TeamPage.new(1) }
327
268
 
269
+ it "responds to all attributes of corresponding AR Class" do
270
+ Team.attribute_names.each do |attribute|
271
+ expect(subject).to respond_to(attribute)
272
+ end
273
+ end
328
274
 
329
- it_behaves_like "it handles filters"
275
+ it "responds <attribute>? of corresponding AR Class" do
276
+ Team.attribute_names.each do |attribute|
277
+ expect(subject).to respond_to("#{attribute}?")
278
+ end
279
+ end
330
280
 
281
+ #
282
+ # Checks a bug
283
+ it "leaves attribute_names of host class intact"
331
284
 
332
- end
285
+ end
333
286
 
334
- context "multiple record found on the page" do
287
+ describe "action method on class" do
288
+ pending
289
+ end
335
290
 
336
- let(:record_number) { 1}
337
- include_context "page with duplicate records"
291
+ describe ".find" do
338
292
 
339
- subject {TeamPage.find(1) }
293
+ subject { TeamPage.find(record_number, selector, filter) }
294
+ let(:selector) { "" }
295
+ let(:filter) { "" }
340
296
 
341
- it "raises error PageRecord::MultipleRecords" do
342
- expect{subject}.to raise_error(PageRecord::MultipleRecords)
343
- end
297
+ context "find without an id" do
298
+ pending
299
+ end
344
300
 
345
- end
301
+ context "one found on the page" do
346
302
 
303
+ let(:record_number) { 1 }
347
304
 
348
- context "no record on the page" do
305
+ it_behaves_like "a valid call of .find"
349
306
 
350
- let(:record_number) { 37373}
307
+ it_behaves_like "it handles filters"
351
308
 
352
- it "raises error PageRecord::RecordNotFound" do
353
- expect{subject}.to raise_error(PageRecord::RecordNotFound)
354
- end
309
+ end
355
310
 
356
- end
311
+ context "multiple record found on the page" do
357
312
 
358
- context "multiple sets of records available on the page" do
359
- include_context "page with two tables with 3 records"
360
- let(:record_number) {1}
313
+ let(:record_number) { 1 }
314
+ include_context "page with duplicate records"
361
315
 
362
- context "without selector" do
363
- let(:selector) {""}
316
+ subject { TeamPage.find(1) }
364
317
 
365
- it "raises error PageRecord::MultipleRecords" do
366
- expect{subject}.to raise_error(PageRecord::MultipleRecords)
367
- end
318
+ it "raises error PageRecord::MultipleRecords" do
319
+ expect { subject }.to raise_error(PageRecord::MultipleRecords)
320
+ end
368
321
 
369
- end
322
+ end
370
323
 
371
- it_behaves_like "handles invalid selectors"
324
+ context "no record on the page" do
372
325
 
373
- context "with a correct selector" do
326
+ let(:record_number) { 37373 }
374
327
 
375
- let(:selector) {"#first-table"}
376
- it_behaves_like "a valid call of .find"
328
+ it "raises error PageRecord::RecordNotFound" do
329
+ expect { subject }.to raise_error(PageRecord::RecordNotFound)
330
+ end
377
331
 
378
- end
332
+ end
379
333
 
380
- end
334
+ context "multiple sets of records available on the page" do
335
+ include_context "page with two tables with 3 records"
336
+ let(:record_number) { 1 }
381
337
 
382
- end
338
+ context "without selector" do
339
+ let(:selector) { "" }
383
340
 
384
- describe "find_by..." do
341
+ it "raises error PageRecord::MultipleRecords" do
342
+ expect { subject }.to raise_error(PageRecord::MultipleRecords)
343
+ end
385
344
 
386
- subject { TeamPage.find_by_name(name, selector, filter)}
387
- let(:selector) { ""}
388
- let(:filter) {""}
345
+ end
389
346
 
390
- context "no record on page" do
391
- let(:name) {"unknown name"}
347
+ it_behaves_like "handles invalid selectors"
392
348
 
393
- it "raises error PageRecord::RecordNotFound" do
394
- expect{subject}.to raise_error(PageRecord::RecordNotFound)
395
- end
349
+ context "with a correct selector" do
396
350
 
397
- end
351
+ let(:selector) { "#first-table" }
352
+ it_behaves_like "a valid call of .find"
398
353
 
399
- context "multiple records on page" do
400
- let(:name) {"Ajax"}
401
- include_context "page with duplicate records"
354
+ end
402
355
 
403
- it "raises error PageRecord::MultipleRecords" do
404
- expect{subject}.to raise_error(PageRecord::MultipleRecords)
405
- end
356
+ end
406
357
 
407
- end
358
+ end
408
359
 
409
- context "one record on page" do
410
- let(:name) {"Ajax"}
360
+ describe "find_by..." do
411
361
 
412
- it_behaves_like "a valid call of .find"
413
- it_behaves_like "it handles filters"
362
+ subject { TeamPage.find_by_name(name, selector, filter) }
363
+ let(:selector) { "" }
364
+ let(:filter) { "" }
414
365
 
415
- end
366
+ context "no record on page" do
367
+ let(:name) { "unknown name" }
416
368
 
417
- context "multiple sets of records avialable on the page" do
418
- include_context "page with two tables with 3 records"
419
- let(:name) {"Ajax"}
369
+ it "raises error PageRecord::RecordNotFound" do
370
+ expect { subject }.to raise_error(PageRecord::RecordNotFound)
371
+ end
420
372
 
421
- context "without selector" do
422
- let(:selector) {""}
373
+ end
423
374
 
424
- it "raises error PageRecord::MultipleRecords" do
425
- expect{subject}.to raise_error(PageRecord::MultipleRecords)
426
- end
375
+ context "multiple records on page" do
376
+ let(:name) { "Ajax" }
377
+ include_context "page with duplicate records"
427
378
 
428
- end
379
+ it "raises error PageRecord::MultipleRecords" do
380
+ expect { subject }.to raise_error(PageRecord::MultipleRecords)
381
+ end
429
382
 
430
- it_behaves_like "handles invalid selectors"
383
+ end
431
384
 
432
- context "with a correct selector" do
385
+ context "one record on page" do
386
+ let(:name) { "Ajax" }
433
387
 
434
- let(:selector) {"#first-table"}
435
- let(:name) {"Ajax"}
436
- it_behaves_like "a valid call of .find"
388
+ it_behaves_like "a valid call of .find"
389
+ it_behaves_like "it handles filters"
437
390
 
438
- end
391
+ end
439
392
 
440
- end
393
+ context "multiple sets of records avialable on the page" do
394
+ include_context "page with two tables with 3 records"
395
+ let(:name) { "Ajax" }
441
396
 
397
+ context "without selector" do
398
+ let(:selector) { "" }
442
399
 
400
+ it "raises error PageRecord::MultipleRecords" do
401
+ expect { subject }.to raise_error(PageRecord::MultipleRecords)
402
+ end
443
403
 
444
- end
404
+ end
445
405
 
446
- describe "#...? " do
406
+ it_behaves_like "handles invalid selectors"
447
407
 
448
- subject {TeamPage.find(1)}
408
+ context "with a correct selector" do
449
409
 
450
- context "attribute is on page" do
410
+ let(:selector) { "#first-table" }
411
+ let(:name) { "Ajax" }
412
+ it_behaves_like "a valid call of .find"
451
413
 
452
- it "returns the dom object" do
453
- expect( subject.name?.class).to eq Capybara::Node::Element
454
- end
455
- end
414
+ end
456
415
 
457
- context "attribute not on page" do
416
+ end
458
417
 
459
- it "raises error PageRecord::AttributeNotFound" do
460
- expect{subject.goals?}.to raise_error(PageRecord::AttributeNotFound)
461
- end
418
+ end
462
419
 
463
- end
464
- end
420
+ describe "#...? " do
465
421
 
466
- describe "#... valid attribute getter" do
422
+ subject { TeamPage.find(1) }
467
423
 
468
- subject {TeamPage.find(1)}
469
- include_context "page with single table with 3 records"
424
+ context "attribute is on page" do
470
425
 
471
- context "attribute is on page" do
426
+ it "returns the dom object" do
427
+ expect(subject.name?.class).to eq Capybara::Node::Element
428
+ end
429
+ end
472
430
 
473
- it "returns a the value on the page" do
474
- expect( subject.name).to eq 'Ajax'
475
- end
476
- end
431
+ context "attribute not on page" do
477
432
 
478
- context "attribute not on page" do
433
+ it "raises error PageRecord::AttributeNotFound" do
434
+ expect { subject.goals? }.to raise_error(PageRecord::AttributeNotFound)
435
+ end
479
436
 
480
- it "raises error PageRecord::AttributeNotFound" do
481
- expect{subject.goals}.to raise_error(PageRecord::AttributeNotFound)
482
- end
437
+ end
438
+ end
483
439
 
484
- end
440
+ describe "#... valid attribute getter" do
485
441
 
442
+ subject { TeamPage.find(1) }
443
+ include_context "page with single table with 3 records"
486
444
 
487
- end
445
+ context "attribute is on page" do
488
446
 
489
- describe "#... valid attribute setter" do
447
+ it "returns a the value on the page" do
448
+ expect(subject.name).to eq 'Ajax'
449
+ end
450
+ end
490
451
 
491
- subject {record.name = 'FC Utrecht'}
492
- let(:record) { TeamPage.find(1)}
452
+ context "attribute not on page" do
493
453
 
454
+ it "raises error PageRecord::AttributeNotFound" do
455
+ expect { subject.goals }.to raise_error(PageRecord::AttributeNotFound)
456
+ end
494
457
 
495
- context "attribute is an input field" do
496
- include_context "page one record in a form"
458
+ end
497
459
 
498
- it "sets the attribute to specified value" do
499
- expect{subject}.to change{record.name}.from(nil).to('FC Utrecht')
500
- end
501
- end
460
+ end
502
461
 
503
- context "attribute is an input field" do
504
- include_context "page one record"
462
+ describe "#... valid attribute setter" do
505
463
 
506
- it "raises error PageRecord::NotInputField" do
507
- expect{subject}.to raise_error(PageRecord::NotInputField)
508
- end
464
+ subject { record.name = 'FC Utrecht' }
465
+ let(:record) { TeamPage.find(1) }
509
466
 
510
- end
467
+ context "attribute is an input field" do
468
+ include_context "page one record in a form"
511
469
 
512
- end
470
+ it "sets the attribute to specified value" do
471
+ expect { subject }.to change { record.name }.from(nil).to('FC Utrecht')
472
+ end
473
+ end
513
474
 
514
- describe "#... action methods" do
475
+ context "attribute is an input field" do
476
+ include_context "page one record"
515
477
 
516
- let(:record) { TeamPage.find(1)}
517
- include_context "page one record in a form"
478
+ it "raises error PageRecord::NotInputField" do
479
+ expect { subject }.to raise_error(PageRecord::NotInputField)
480
+ end
518
481
 
519
- context "action exists on page" do
520
- subject {record.create}
482
+ end
521
483
 
522
- it "clicks on the specified action element" do
523
- expect{subject}.not_to raise_error(PageRecord::NotInputField) # TODO can we make it better?
524
- end
484
+ end
525
485
 
486
+ describe "#... action methods" do
526
487
 
527
- end
488
+ let(:record) { TeamPage.find(1) }
489
+ include_context "page one record in a form"
528
490
 
529
- context "action doesn't exist on page" do
530
- subject {record.unkown}
491
+ context "action exists on page" do
492
+ subject { record.create }
531
493
 
532
- it "raises error NoMethodError" do
533
- expect{subject}.to raise_error(NoMethodError)
534
- end
535
- end
494
+ it "clicks on the specified action element" do
495
+ expect { subject }.not_to raise_error
496
+ end
536
497
 
498
+ end
537
499
 
538
- end
500
+ context "action doesn't exist on page" do
501
+ subject { record.unkown }
539
502
 
540
- describe "#...? action methods" do
541
- pending
542
- end
503
+ it "raises error NoMethodError" do
504
+ expect { subject }.to raise_error(NoMethodError)
505
+ end
506
+ end
543
507
 
544
- describe ".attributes" do
545
- pending
546
- end
508
+ end
547
509
 
548
- describe "found bugs" do
510
+ describe "#...? action methods" do
511
+ pending
512
+ end
549
513
 
550
- describe "class name contains word page but doens't exist" do
514
+ describe ".attributes" do
515
+ pending
516
+ end
551
517
 
552
- it "doesn'throw exception" do
553
- expect { class RubbishPage < PageRecord::Base; end }.not_to raise_error
554
- end
518
+ describe "found bugs" do
555
519
 
556
- end
520
+ describe "class name contains word page but doens't exist" do
557
521
 
522
+ it "doesn'throw exception" do
523
+ expect { class RubbishPage < PageRecord::Base; end }.not_to raise_error
524
+ end
558
525
 
559
- end
526
+ end
560
527
 
528
+ end
561
529
 
562
- end
530
+ end
531
+ # rubocop:enable StringLiterals