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