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/spec_helper.rb
CHANGED
@@ -8,12 +8,11 @@ require 'coveralls'
|
|
8
8
|
Coveralls.wear!
|
9
9
|
|
10
10
|
if defined?(ActionView::Base)
|
11
|
-
|
11
|
+
require 'rails'
|
12
12
|
require 'rspec/rails/mocks'
|
13
13
|
include RSpec::Rails::Mocks
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
require 'page_record'
|
18
17
|
require 'capybara'
|
19
18
|
require 'capybara/dsl'
|
@@ -27,7 +26,6 @@ require_relative './support/shared_examples'
|
|
27
26
|
Capybara.app = TestApp
|
28
27
|
Capybara.app_host = nil
|
29
28
|
|
30
|
-
|
31
29
|
RSpec.configure do |config|
|
32
30
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
33
31
|
config.run_all_when_everything_filtered = true
|
@@ -10,7 +10,6 @@ shared_context "page with two tables with 3 records" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
13
|
shared_context "page without records" do
|
15
14
|
before do
|
16
15
|
visit "/page-without-records"
|
@@ -29,9 +28,32 @@ shared_context "page one record in a form" do
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
31
|
shared_context "page one record" do
|
34
32
|
before do
|
35
33
|
visit "/page-one-record"
|
36
34
|
end
|
37
35
|
end
|
36
|
+
|
37
|
+
shared_context "page without errors" do
|
38
|
+
before do
|
39
|
+
visit "/page-without-errors"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
shared_context "page with 1 error" do
|
44
|
+
before do
|
45
|
+
visit "/page-with-1-error"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
shared_context "page with 2 errors on same attribute" do
|
50
|
+
before do
|
51
|
+
visit "/page-with-2-errors-on-same-attribute"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
shared_context "page with 2 errors on different attributes" do
|
56
|
+
before do
|
57
|
+
visit "/page-with-2-errors-on-different-attributes"
|
58
|
+
end
|
59
|
+
end
|
@@ -1,71 +1,67 @@
|
|
1
1
|
shared_examples "valid call of .all" do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
it "returns an Array" do
|
4
|
+
expect(subject.class).to eq Array
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
it "returns the inheriting class in the Array" do
|
8
|
+
subject.each do |record|
|
9
|
+
expect(record.class).to eq TeamPage
|
10
|
+
end
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
it "returns an element for each record on the page" do
|
14
|
+
expect(subject.count).to eq 3
|
15
|
+
end
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
shared_examples "it handles filters" do
|
21
|
-
|
22
|
-
|
20
|
+
context "specified record contains specified filter" do
|
21
|
+
let(:filter) { ".champions_league" }
|
23
22
|
|
24
|
-
|
23
|
+
it_behaves_like "a valid call of .find"
|
25
24
|
|
26
|
-
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
context "specified record doesn't contain specified filter" do
|
28
|
+
let(:filter) { ".euro_league" }
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
it "raises error PageRecord::RecordNotFound" do
|
31
|
+
expect { subject }.to raise_error(PageRecord::RecordNotFound)
|
32
|
+
end
|
33
|
+
end
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
36
|
shared_examples "handles invalid selectors" do
|
39
|
-
|
40
|
-
|
41
|
-
let(:selector) {"#non-existing-table"}
|
42
|
-
let(:filter) {""}
|
43
|
-
|
37
|
+
context "with an non existing selector" do
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
39
|
+
let(:selector) { "#non-existing-table" }
|
40
|
+
let(:filter) { "" }
|
49
41
|
|
50
|
-
|
42
|
+
it "raises error PageRecord::RecordNotFound" do
|
43
|
+
expect { subject }.to raise_error(PageRecord::RecordNotFound)
|
44
|
+
end
|
45
|
+
end
|
51
46
|
|
52
|
-
|
53
|
-
let(:filter) {""}
|
47
|
+
context "with an undetermined selector" do
|
54
48
|
|
49
|
+
let(:selector) { ".team-table" }
|
50
|
+
let(:filter) { "" }
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
it "raises error PageRecord::MultipleRecords" do
|
53
|
+
expect { subject }.to raise_error(PageRecord::MultipleRecords)
|
54
|
+
end
|
59
55
|
|
60
|
-
|
56
|
+
end
|
61
57
|
end
|
62
58
|
|
63
59
|
shared_examples "a valid call of .find" do
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
it "returns the inheriting class" do
|
61
|
+
expect(subject.class).to eq TeamPage
|
62
|
+
end
|
67
63
|
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
it "returns the record identified by the id" do
|
65
|
+
expect(subject.id).to eq '1'
|
66
|
+
end
|
71
67
|
end
|
data/spec/support/team.rb
CHANGED
data/spec/support/test_app.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
|
-
|
4
3
|
# @private This is just a test class
|
5
4
|
class TestApp < Sinatra::Base
|
6
5
|
|
7
6
|
set :root, File.dirname(__FILE__)
|
8
7
|
set :raise_errors, true
|
9
|
-
# set :show_exceptions, false
|
10
|
-
|
11
8
|
|
12
9
|
get '/*' do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
viewname = params[:splat].first # eg "some/path/here"
|
11
|
+
if File.exist?("#{settings.root}/views/#{viewname}.erb")
|
12
|
+
erb :"#{viewname}"
|
13
|
+
else
|
14
|
+
"can't find view #{viewname}"
|
15
|
+
end
|
16
|
+
end
|
20
17
|
end
|
21
18
|
|
22
|
-
if __FILE__ == $
|
23
|
-
Rack::Handler::WEBrick.run TestApp, :
|
24
|
-
end
|
19
|
+
if __FILE__ == $PROGRAM_NAME
|
20
|
+
Rack::Handler::WEBrick.run TestApp, Port: 8070
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<form data-team-id='1'>
|
2
|
+
<div data-error-for='name'>this is the validation message for name</div>
|
3
|
+
<input data-attribute-for='name'>
|
4
|
+
|
5
|
+
<div data-error-for='age'>this is the validation message for age</div>
|
6
|
+
<input data-attribute-for='age'>
|
7
|
+
|
8
|
+
<button data-action-for='create'>
|
9
|
+
</form>
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
describe "Page Record validations" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
class TeamPage < PageRecord::Base; end
|
7
|
+
PageRecord::Base.page page
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:record) { TeamPage.find}
|
11
|
+
|
12
|
+
describe '#errors' do
|
13
|
+
|
14
|
+
subject {record.errors}
|
15
|
+
|
16
|
+
|
17
|
+
context "No errors on the page" do
|
18
|
+
|
19
|
+
include_context "page without errors"
|
20
|
+
|
21
|
+
it "is empty" do
|
22
|
+
expect(subject).to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "1 error on the page" do
|
27
|
+
include_context "page with 1 error"
|
28
|
+
|
29
|
+
it "returns an Error object with the atrribute and error" do
|
30
|
+
expect(subject[:name]).to eq ['this is the validation message']
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "more errors on the same attribute" do
|
36
|
+
include_context "page with 2 errors on same attribute"
|
37
|
+
|
38
|
+
it "returns an Error object with the atrributes and errors" do
|
39
|
+
expect(subject[:name]).to eq ['this is the first validation message', 'this is the second validation message']
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
context "more errors on the different attributes" do
|
45
|
+
include_context "page with 2 errors on different attributes"
|
46
|
+
|
47
|
+
it "returns an Error object with the atrributes and errors" do
|
48
|
+
expect(subject[:name]).to eq ['this is the validation message for name']
|
49
|
+
expect(subject[:age]).to eq ['this is the validation message for age']
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#valid?' do
|
58
|
+
|
59
|
+
subject { record.valid?}
|
60
|
+
|
61
|
+
context "No errors on the page" do
|
62
|
+
include_context "page without errors"
|
63
|
+
|
64
|
+
it 'is true' do
|
65
|
+
expect(subject).to be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "1 error on the page" do
|
71
|
+
include_context "page with 1 error"
|
72
|
+
|
73
|
+
it 'is false' do
|
74
|
+
expect(subject).to be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "more errors on the same attribute" do
|
81
|
+
include_context "page with 2 errors on same attribute"
|
82
|
+
|
83
|
+
it 'is false' do
|
84
|
+
expect(subject).to be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "more errors on the different attributes" do
|
89
|
+
include_context "page with 2 errors on different attributes"
|
90
|
+
|
91
|
+
it 'is false' do
|
92
|
+
expect(subject).to be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#invalid?' do
|
100
|
+
|
101
|
+
subject { record.invalid?}
|
102
|
+
|
103
|
+
context "No errors on the page" do
|
104
|
+
include_context "page without errors"
|
105
|
+
|
106
|
+
it 'is false' do
|
107
|
+
expect(subject).to be_false
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
context "1 error on the page" do
|
113
|
+
include_context "page with 1 error"
|
114
|
+
|
115
|
+
it 'is true' do
|
116
|
+
expect(subject).to be_true
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
context "more errors on the same attribute" do
|
123
|
+
include_context "page with 2 errors on same attribute"
|
124
|
+
|
125
|
+
it 'is true' do
|
126
|
+
expect(subject).to be_true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "more errors on the different attributes" do
|
131
|
+
include_context "page with 2 errors on different attributes"
|
132
|
+
|
133
|
+
it 'is true' do
|
134
|
+
expect(subject).to be_true
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
./spec/inspector_spec.rb:12
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,6 +123,38 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: ruby_gntp
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
126
158
|
- !ruby/object:Gem::Dependency
|
127
159
|
name: capybara
|
128
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,11 +187,31 @@ dependencies:
|
|
155
187
|
- - ! '>='
|
156
188
|
- !ruby/object:Gem::Version
|
157
189
|
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: activemodel
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :runtime
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
158
206
|
description: Page Object implementation with ActiveRecord like reading from specialy
|
159
207
|
formatted HTML-page
|
160
208
|
email:
|
161
209
|
- hajee@moretIA.com
|
162
|
-
executables:
|
210
|
+
executables:
|
211
|
+
- autospec
|
212
|
+
- guard
|
213
|
+
- rake
|
214
|
+
- rspec
|
163
215
|
extensions: []
|
164
216
|
extra_rdoc_files: []
|
165
217
|
files:
|
@@ -167,14 +219,20 @@ files:
|
|
167
219
|
- .gitignore
|
168
220
|
- .gitmodules
|
169
221
|
- .rspec
|
222
|
+
- .rubocop.yml
|
170
223
|
- .travis.yml
|
171
224
|
- .yardopts
|
172
225
|
- CHANGES.md
|
173
226
|
- Gemfile
|
174
227
|
- Gemfile.lock
|
228
|
+
- Guardfile
|
175
229
|
- LICENSE.txt
|
176
230
|
- README.md
|
177
231
|
- Rakefile
|
232
|
+
- bin/autospec
|
233
|
+
- bin/guard
|
234
|
+
- bin/rake
|
235
|
+
- bin/rspec
|
178
236
|
- lib/page_record.rb
|
179
237
|
- lib/page_record/attribute_accessors.rb
|
180
238
|
- lib/page_record/base.rb
|
@@ -186,11 +244,15 @@ files:
|
|
186
244
|
- lib/page_record/form_builder.rb
|
187
245
|
- lib/page_record/formtastic.rb
|
188
246
|
- lib/page_record/helpers.rb
|
247
|
+
- lib/page_record/inspector.rb
|
189
248
|
- lib/page_record/instance_actions.rb
|
190
249
|
- lib/page_record/rspec.rb
|
250
|
+
- lib/page_record/validation.rb
|
191
251
|
- lib/page_record/version.rb
|
192
252
|
- page_record.gemspec
|
253
|
+
- spec/.rubocop.yml
|
193
254
|
- spec/helpers_spec.rb
|
255
|
+
- spec/inspector_spec.rb
|
194
256
|
- spec/page_record_spec.rb
|
195
257
|
- spec/spec_helper.rb
|
196
258
|
- spec/support/shared_contexts.rb
|
@@ -199,10 +261,16 @@ files:
|
|
199
261
|
- spec/support/test_app.rb
|
200
262
|
- spec/support/views/page-one-record-in-a-form.erb
|
201
263
|
- spec/support/views/page-one-record.erb
|
264
|
+
- spec/support/views/page-with-1-error.erb
|
265
|
+
- spec/support/views/page-with-2-errors-on-different-attributes.erb
|
266
|
+
- spec/support/views/page-with-2-errors-on-same-attribute.erb
|
202
267
|
- spec/support/views/page-with-duplicate-records.erb
|
203
268
|
- spec/support/views/page-with-single-table-with-3-records.erb
|
204
269
|
- spec/support/views/page-with-two-tables-with-3-records.erb
|
270
|
+
- spec/support/views/page-without-errors.erb
|
205
271
|
- spec/support/views/page-without-records.erb
|
272
|
+
- spec/validation_spec.rb
|
273
|
+
- tmp/rspec_guard_result
|
206
274
|
homepage: https://github.com/appdrones/page_record
|
207
275
|
licenses:
|
208
276
|
- MIT
|
@@ -218,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
286
|
version: '0'
|
219
287
|
segments:
|
220
288
|
- 0
|
221
|
-
hash:
|
289
|
+
hash: 3974073958199987845
|
222
290
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
291
|
none: false
|
224
292
|
requirements:
|
@@ -227,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
295
|
version: '0'
|
228
296
|
segments:
|
229
297
|
- 0
|
230
|
-
hash:
|
298
|
+
hash: 3974073958199987845
|
231
299
|
requirements: []
|
232
300
|
rubyforge_project:
|
233
301
|
rubygems_version: 1.8.24
|
@@ -236,7 +304,9 @@ specification_version: 3
|
|
236
304
|
summary: Page Object implementation. Using some specialy formatted 'data-...' tags
|
237
305
|
you can read records from HTML pages like an ActiveRecord page
|
238
306
|
test_files:
|
307
|
+
- spec/.rubocop.yml
|
239
308
|
- spec/helpers_spec.rb
|
309
|
+
- spec/inspector_spec.rb
|
240
310
|
- spec/page_record_spec.rb
|
241
311
|
- spec/spec_helper.rb
|
242
312
|
- spec/support/shared_contexts.rb
|
@@ -245,7 +315,12 @@ test_files:
|
|
245
315
|
- spec/support/test_app.rb
|
246
316
|
- spec/support/views/page-one-record-in-a-form.erb
|
247
317
|
- spec/support/views/page-one-record.erb
|
318
|
+
- spec/support/views/page-with-1-error.erb
|
319
|
+
- spec/support/views/page-with-2-errors-on-different-attributes.erb
|
320
|
+
- spec/support/views/page-with-2-errors-on-same-attribute.erb
|
248
321
|
- spec/support/views/page-with-duplicate-records.erb
|
249
322
|
- spec/support/views/page-with-single-table-with-3-records.erb
|
250
323
|
- spec/support/views/page-with-two-tables-with-3-records.erb
|
324
|
+
- spec/support/views/page-without-errors.erb
|
251
325
|
- spec/support/views/page-without-records.erb
|
326
|
+
- spec/validation_spec.rb
|