page_record 1.0.1 → 1.0.3

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/CHANGES.md CHANGED
@@ -1,28 +1,39 @@
1
1
  #Changes
2
2
 
3
- ##V0.2.0
4
- * __BREAKING CHANGE__ Changed class name `PageRecord::PageRecord` to `PageRecord::Base`. Just a rename should be enough.
5
- * Added `add_attributes` class method. This allows you to just add extra attributes instead of specifying them all
6
- * Added `host_class` class method. Now you are able to set any class as a host class instead of beeing glued to xxxxPage`
3
+ ##V1.0.3
4
+ * Added support for getting the Capybara element of a record.
5
+ * #id now returns an integer
7
6
 
8
- ##V0.2.1
9
- * Fixed a bug. PageRecord stack dumped when the class contained the name `Page`
7
+ ##V1.0.2
8
+ * Added the id of the record to the inspector.
9
+ * inspecting uses the Array variant of Capybara and doesn't wait.
10
10
 
11
- ##V0.3.0
12
- * Added rails helpers to make it easy in rails to have a form, recognised by PageRecord
13
- * Added other helpers to mke it easy to add `actions` and `attribute` tags
11
+ ##V1.0.1
12
+ * Fixed a bug in action handling that causes page actions aoutside of a record te be noticed. Refactored the action handling.
14
13
 
15
- ##V0.4.0
16
- * Added support for Formtasic
17
- * Added spec's for rails helpers
14
+ ##V1.0.0
15
+ Released to production
18
16
 
19
17
  ##V0.5.0
20
18
  * Added a rails project containing some cucumber features to demonstrate how it works. The example also shows how to use the rails and Formtastic helpers.
21
19
  * Added support for form validations. Both in formtastic and in reading the errors
22
20
  * added a `inspect` for both the class and for the instances. This is __very__ helpfull when dubugging.
23
21
 
24
- ##V1.0.0
25
- Released to production
22
+ ##V0.4.0
23
+ * Added support for Formtasic
24
+ * Added spec's for rails helpers
25
+
26
+ ##V0.3.0
27
+ * Added rails helpers to make it easy in rails to have a form, recognised by PageRecord
28
+ * Added other helpers to mke it easy to add `actions` and `attribute` tags
29
+
30
+ ##V0.2.1
31
+ * Fixed a bug. PageRecord stack dumped when the class contained the name `Page`
32
+
33
+ ##V0.2.0
34
+ * __BREAKING CHANGE__ Changed class name `PageRecord::PageRecord` to `PageRecord::Base`. Just a rename should be enough.
35
+ * Added `add_attributes` class method. This allows you to just add extra attributes instead of specifying them all
36
+ * Added `host_class` class method. Now you are able to set any class as a host class instead of beeing glued to xxxxPage`
37
+
38
+
26
39
 
27
- ##V1.0.1
28
- Fixed a bug in action handling that causes page actions aoutside of a record te be noticed. Refactored the action handling.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- page_record (1.0.1)
4
+ page_record (1.0.3)
5
5
  activemodel
6
6
  activesupport
7
7
  capybara (~> 2.1.0)
@@ -31,7 +31,7 @@ GEM
31
31
  thread_safe (~> 0.1)
32
32
  tzinfo (~> 0.3.37)
33
33
  arel (4.0.0)
34
- atomic (1.1.10)
34
+ atomic (1.1.13)
35
35
  builder (3.1.4)
36
36
  capybara (2.1.0)
37
37
  mime-types (>= 1.16)
@@ -51,7 +51,7 @@ GEM
51
51
  erubis (2.7.0)
52
52
  ffi (1.9.0)
53
53
  formatador (0.2.4)
54
- guard (1.8.1)
54
+ guard (1.8.2)
55
55
  formatador (>= 0.2.4)
56
56
  listen (>= 1.0.0)
57
57
  lumberjack (>= 1.0.2)
@@ -60,17 +60,17 @@ GEM
60
60
  guard-rspec (3.0.2)
61
61
  guard (>= 1.8)
62
62
  rspec (~> 2.13)
63
- i18n (0.6.4)
64
- listen (1.2.2)
63
+ i18n (0.6.5)
64
+ listen (1.3.0)
65
65
  rb-fsevent (>= 0.9.3)
66
66
  rb-inotify (>= 0.9)
67
67
  rb-kqueue (>= 0.2)
68
68
  lumberjack (1.0.4)
69
69
  method_source (0.8.2)
70
- mime-types (1.23)
70
+ mime-types (1.24)
71
71
  mini_portile (0.5.1)
72
72
  minitest (4.7.5)
73
- multi_json (1.7.7)
73
+ multi_json (1.7.9)
74
74
  nokogiri (1.6.0)
75
75
  mini_portile (~> 0.5.0)
76
76
  pry (0.9.12.2)
@@ -89,7 +89,7 @@ GEM
89
89
  thor (>= 0.18.1, < 2.0)
90
90
  rake (10.1.0)
91
91
  rb-fsevent (0.9.3)
92
- rb-inotify (0.9.0)
92
+ rb-inotify (0.9.1)
93
93
  ffi (>= 0.5.0)
94
94
  rb-kqueue (0.2.0)
95
95
  ffi (>= 0.5.0)
@@ -99,10 +99,10 @@ GEM
99
99
  rspec-core (~> 2.14.0)
100
100
  rspec-expectations (~> 2.14.0)
101
101
  rspec-mocks (~> 2.14.0)
102
- rspec-core (2.14.4)
103
- rspec-expectations (2.14.0)
102
+ rspec-core (2.14.5)
103
+ rspec-expectations (2.14.2)
104
104
  diff-lcs (>= 1.1.3, < 2.0)
105
- rspec-mocks (2.14.2)
105
+ rspec-mocks (2.14.3)
106
106
  rspec-rails (2.14.0)
107
107
  actionpack (>= 3.0)
108
108
  activesupport (>= 3.0)
@@ -25,7 +25,11 @@ module PageRecord
25
25
  # @raise [AttributeNotFound] when the attribute is not found in the record
26
26
  #
27
27
  def read_attribute(attribute)
28
- element = send("#{attribute}?")
28
+ if block_given?
29
+ element = yield
30
+ else
31
+ element = send("#{attribute}?")
32
+ end
29
33
  tag = element.tag_name
30
34
  input_field?(tag) ? element.value : element.text
31
35
  end
@@ -13,10 +13,25 @@ module PageRecord
13
13
  def initialize(id = nil, selector = nil, filter = nil)
14
14
  @page = self.class.page
15
15
  @type = self.class.instance_variable_get('@type')
16
- @id = id.to_s
16
+ @id = id.to_i if id
17
17
  find_record(selector, filter)
18
18
  end
19
19
 
20
+ ##
21
+ # Return the Capybara element containg the record
22
+ #
23
+ # Example:
24
+ #
25
+ # ```ruby
26
+ # team_1 = TeamPage.find(1) # Get the first team
27
+ # team_1.element? # access the Capybara context
28
+ # end
29
+ # ```
30
+ #
31
+ def element?
32
+ @record
33
+ end
34
+
20
35
  ##
21
36
  # Set's the default selector for this class
22
37
  #
@@ -274,7 +289,7 @@ module PageRecord
274
289
  begin
275
290
  context = self.class.context_for_selector(selector)
276
291
  @record = context.find("[data-#{@type}-id#{id_text}]#{filter}")
277
- @id = @record["data-#{@type}-id"] if @id.blank?
292
+ @id = @record["data-#{@type}-id"].to_i if @id.blank?
278
293
  rescue Capybara::Ambiguous
279
294
  raise MultipleRecords, "Found multiple #{@type} record with id #{@id} on page"
280
295
  rescue Capybara::ElementNotFound
@@ -20,12 +20,15 @@ module PageRecord
20
20
  attributes = {}
21
21
  self.class.attributes.each do | attribute|
22
22
  begin
23
- attributes[attribute] = send(attribute)
24
- rescue AttributeNotFound
23
+ attributes[attribute] = read_attribute(attribute) do
24
+ @record.all("[data-attribute-for='#{attribute}']").first
25
+ end
26
+ rescue NoMethodError
25
27
  attributes[attribute] = '--not found on page--'
26
28
  end
27
29
  end
28
- attributes
30
+ attributes['id'] = id
31
+ attributes
29
32
  end
30
33
 
31
34
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module PageRecord
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -4,6 +4,16 @@ describe PageRecord::Attributes do
4
4
 
5
5
  include_context "default context"
6
6
 
7
+ describe "#id" do
8
+
9
+ subject { TeamPage.find(1) }
10
+ include_context "page with single table with 3 records"
11
+
12
+ it "returns the id as an integer" do
13
+ expect(subject.id).to eq 1
14
+ end
15
+ end
16
+
7
17
  describe "#... valid attribute getter" do
8
18
 
9
19
  subject { TeamPage.find(1) }
data/spec/base_spec.rb CHANGED
@@ -207,6 +207,23 @@ describe PageRecord::Base do
207
207
 
208
208
  end
209
209
 
210
+ describe "record.element?" do
211
+
212
+ subject { TeamPage.find().element? }
213
+
214
+ context "record on the page" do
215
+ before do
216
+ visit '/page-one-record'
217
+ end
218
+
219
+ it "returns the capybara element containing the record" do
220
+ expect(subject.class).to eq Capybara::Node::Element
221
+ end
222
+
223
+ end
224
+ end
225
+
226
+
210
227
  describe "found bugs" do
211
228
 
212
229
  describe "class name contains word page but doens't exist" do
@@ -61,6 +61,7 @@ describe PageRecord::Inspector do
61
61
  subject { TeamPage.find(1).inspect }
62
62
 
63
63
  it 'returns all attributes' do
64
+ expect(subject[:attributes]['id']).to eq 1
64
65
  expect(subject[:attributes]['ranking']).to eq '1'
65
66
  expect(subject[:attributes]['name']).to eq 'Ajax'
66
67
  expect(subject[:attributes]['points']).to eq '10'
@@ -26,7 +26,7 @@ shared_examples "a valid single record finder" do
26
26
  end
27
27
 
28
28
  it "returns the record identified by the id" do
29
- expect(subject.id).to eq '1'
29
+ expect(subject.id).to eq 1
30
30
  end
31
31
 
32
32
  end
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: 1.0.1
4
+ version: 1.0.3
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-08-17 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -293,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
293
  version: '0'
294
294
  segments:
295
295
  - 0
296
- hash: -1859319199446950175
296
+ hash: 1953905507343366230
297
297
  required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  none: false
299
299
  requirements:
@@ -302,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
302
  version: '0'
303
303
  segments:
304
304
  - 0
305
- hash: -1859319199446950175
305
+ hash: 1953905507343366230
306
306
  requirements: []
307
307
  rubyforge_project:
308
308
  rubygems_version: 1.8.24