page_record 1.0.0 → 1.0.1

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
@@ -20,3 +20,9 @@
20
20
  * 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
21
  * Added support for form validations. Both in formtastic and in reading the errors
22
22
  * added a `inspect` for both the class and for the instances. This is __very__ helpfull when dubugging.
23
+
24
+ ##V1.0.0
25
+ Released to production
26
+
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.0)
4
+ page_record (1.0.1)
5
5
  activemodel
6
6
  activesupport
7
7
  capybara (~> 2.1.0)
@@ -2,58 +2,31 @@ module PageRecord
2
2
  module Actions
3
3
 
4
4
  def self.included(base)
5
+ base.class_eval do
6
+ include(ActionHandler)
7
+ end
8
+ base.extend(ActionHandler)
5
9
  base.extend(ClassMethods)
6
10
  end
7
11
 
8
- ##
9
- # This is the implementation of the record action routine. It has two variants.
10
- # it has a `?` variant and a `normal` variant.
11
- #
12
- # normal variant:
13
- # It checks the page for a data-action-for='action' tag somewhere on the page.
14
- # If it finds it, it clicks it.
15
- #
16
- # `?` variant:
17
- # It checks the page for a data-action-for='action' tag somewhere on the page.
18
- # If it finds it, returns the Capybara element.
19
- #
20
- # @param action [Symbol] this is the name of the action
21
- #
22
- # @return [Capybara::Result]
23
- #
24
- # @raise [PageRecord::MultipleRecords] when there are more actions with
25
- # this name on the page
26
- #
27
- def method_missing(action)
28
- self.class.method_missing(action)
29
- end
30
-
31
12
  protected
32
13
 
33
14
  # @private
34
15
  def actions
35
- self.class.send('actions_on?', @record)
16
+ actions_on?(@record)
36
17
  end
37
18
 
38
19
  private
39
20
 
40
- # @private
41
- def action_for(action)
42
- element = action_for?(action)
43
- element.click
44
- element
45
- end
46
-
47
21
  # @private
48
22
  def action_for?(action)
49
23
  @record.find("[data-action-for='#{action}']")
50
24
  end
51
25
 
52
- module ClassMethods
53
-
26
+ module ActionHandler
54
27
  ##
55
28
  #
56
- # This is the implementation of the page action routine. It has two variants.
29
+ # This is the implementation of the page and record action routine. It has two variants.
57
30
  # it has a `?` variant and a `normal` variant.
58
31
  #
59
32
  # normal variant:
@@ -69,9 +42,9 @@ module PageRecord
69
42
  # @return [Capybara::Element]
70
43
  #
71
44
  # @raise [PageRecord::MultipleRecords] when there are more actions with
72
- # this name on the page
45
+ # this name on the page/record
73
46
  #
74
- def method_missing(action)
47
+ def method_missing(action, message = nil)
75
48
  raw_action = /(.*)\?/.match(action)
76
49
  begin
77
50
  if raw_action
@@ -80,17 +53,20 @@ module PageRecord
80
53
  action_for(action)
81
54
  end
82
55
  rescue Capybara::Ambiguous
83
- raise MultipleRecords, "Found multiple #{action} tags for #{@type} on page"
56
+ message ||= "Found multiple #{action} tags for #{@type} on page"
57
+ raise MultipleRecords, message
84
58
  rescue Capybara::ElementNotFound
85
59
  super
86
60
  end
87
61
  end
88
62
 
89
- protected
63
+ private
90
64
 
91
65
  # @private
92
- def actions
93
- actions_on?(page)
66
+ def action_for(action)
67
+ element = action_for?(action)
68
+ element.click
69
+ element
94
70
  end
95
71
 
96
72
  # @private
@@ -104,15 +80,19 @@ module PageRecord
104
80
  action_hash
105
81
  end
106
82
 
107
- private
83
+ end
84
+
85
+ module ClassMethods
86
+
87
+ protected
108
88
 
109
89
  # @private
110
- def action_for(action)
111
- element = action_for?(action)
112
- element.click
113
- element
90
+ def actions
91
+ actions_on?(page)
114
92
  end
115
93
 
94
+ private
95
+
116
96
  # @private
117
97
  def action_for?(action)
118
98
  page.find("[data-action-for='#{action}']")
@@ -1,3 +1,3 @@
1
1
  module PageRecord
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/spec/actions_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe PageRecord::Actions do
18
18
 
19
19
  it_behaves_like "a valid action finder" do
20
20
  let(:valid_action) { record.create}
21
- let(:invalid_action) { record.unkown_action }
21
+ let(:invalid_action) { record.page_action } # It should not see the page action
22
22
  let(:multiple_actions) { record.multiple_action }
23
23
  end
24
24
  end
@@ -29,7 +29,7 @@ describe PageRecord::Actions do
29
29
 
30
30
  it_behaves_like "a valid action finder" do
31
31
  let(:valid_action) { record.create?}
32
- let(:invalid_action) { record.unkown_action?}
32
+ let(:invalid_action) { record.page_action?} # It should not see the page action
33
33
  let(:multiple_actions) { record.multiple_action? }
34
34
  end
35
35
  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.0
4
+ version: 1.0.1
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-01 00:00:00.000000000 Z
12
+ date: 2013-08-17 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: -2075293908552709034
296
+ hash: -1859319199446950175
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: -2075293908552709034
305
+ hash: -1859319199446950175
306
306
  requirements: []
307
307
  rubyforge_project:
308
308
  rubygems_version: 1.8.24