page_magic 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a818b71ddcc138a95601f724bcae9b6631bf87431a9bbd7edb0816f1bdac5fb8
4
- data.tar.gz: 2d6a165aec8c854e49496c6375154c90aa714b97e28f00fa5cefc5d954fe8dd0
3
+ metadata.gz: 6da71e330b1c223cf3bae293c485653388c8e7db834f6c4fc3ac1de274763a46
4
+ data.tar.gz: da53a97958f3a55557dfb23b0b67054d6375b0f7151777b24d0e7046d982f871
5
5
  SHA512:
6
- metadata.gz: 6145762ea0b3ddc8cea37e04957a95873b6d892798efe051d1f3e3937ebc9c6487e1ab9123dc02544190cf77ac3957197dcd0eaf14e87ce5b104c682aee21696
7
- data.tar.gz: d5fc4d9729c2a68bab771e0f4538ed4346daa91a23a53b65cacbe8b75fff02e1ee83e68eef87f77bc5925852a2b1fbd0520e0f3bff2b85f5a2653f408c231faf
6
+ metadata.gz: 292d751ef686fad2d35b21c90c59b89b906ec1173a1d2c4ded593760e9890cd0152c535899a70fc6c887525e96b8a56b5c5708247caf8aa84fb2f768d10ebcf2
7
+ data.tar.gz: b7e9e00a2c766aa9e6e98087e9e5d7bd0ac04498f256a5854667558d8e5f4bb21a22b1cdbcaa8b016ca18cc6c5521ca6169266226a89c93387228e2305f702b5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -73,7 +73,9 @@ module PageMagic
73
73
  # Selector built using supplied configuration
74
74
  # @return [PageMagic::Element::Selector::Model]
75
75
  def selector
76
- selector = self[:selector]
76
+ selector = self[:selector] || definition_class.selector
77
+ raise PageMagic::InvalidConfigurationException, INVALID_SELECTOR_MSG unless validate_selector?(selector)
78
+
77
79
  Element::Selector.find(selector.keys.first).build(type, selector.values.first, options: options)
78
80
  end
79
81
 
@@ -81,7 +83,6 @@ module PageMagic
81
83
  # @raise [PageMagic::InvalidConfigurationException]
82
84
  # @return [PageMagic::Elements::Config]
83
85
  def validate!
84
- raise PageMagic::InvalidConfigurationException, INVALID_SELECTOR_MSG unless element || valid_selector?
85
86
  raise PageMagic::InvalidConfigurationException, 'element type required' unless type
86
87
  raise PageMagic::InvalidConfigurationException, INVALID_ELEMENT_CLASS_MSG unless valid_element_class?
87
88
 
@@ -90,8 +91,7 @@ module PageMagic
90
91
 
91
92
  private
92
93
 
93
- def valid_selector?
94
- selector = self[:selector]
94
+ def validate_selector?(selector)
95
95
  selector.is_a?(Hash) && !selector.empty?
96
96
  end
97
97
 
@@ -59,6 +59,24 @@ RSpec.describe PageMagic::Elements::Config do
59
59
  expect(options.selector).to eq(PageMagic::Element::Selector.find(:id).build(:field, 'child'))
60
60
  end
61
61
 
62
+ context 'when is empty hash' do
63
+ it 'raises an error' do
64
+ options = described_class.build([{}], :field)
65
+ expect { options.selector }.to raise_exception(PageMagic::InvalidConfigurationException,
66
+ described_class::INVALID_SELECTOR_MSG)
67
+ end
68
+ end
69
+
70
+ context 'when defined on both class and as parameter' do
71
+ it 'uses the supplied selector' do
72
+ options = described_class.build([{ css: 'supplied_selector' }], :field)
73
+ options.definition_class = Class.new(PageMagic::Element) do
74
+ selector css: 'class_selector'
75
+ end
76
+ expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'supplied_selector'))
77
+ end
78
+ end
79
+
62
80
  context 'when page_element class supplied' do
63
81
  it 'uses the selector on the class' do
64
82
  expected_selector = { css: 'class' }
@@ -91,6 +109,29 @@ RSpec.describe PageMagic::Elements::Config do
91
109
  end
92
110
  end
93
111
  end
112
+
113
+ context 'when no selector on class or page_element' do
114
+ context 'when dynamically assigned element definition block' do
115
+ it 'uses it' do
116
+ options = described_class.build([], :field)
117
+
118
+ options.definition_class = Class.new(PageMagic::Element) do
119
+ selector({ css: 'class' })
120
+ end
121
+
122
+ expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'class'))
123
+ end
124
+ end
125
+
126
+ context 'when not dynamically assigned' do
127
+ it 'raises and exception' do
128
+ options = described_class.build([], :field)
129
+ options.definition_class = Class.new(PageMagic::Element)
130
+ expect { options.selector }.to raise_exception(PageMagic::InvalidConfigurationException,
131
+ described_class::INVALID_SELECTOR_MSG)
132
+ end
133
+ end
134
+ end
94
135
  end
95
136
 
96
137
  it 'sets prefetched options' do
@@ -119,44 +160,6 @@ RSpec.describe PageMagic::Elements::Config do
119
160
  }
120
161
  end
121
162
 
122
- describe 'selector' do
123
- context 'when nil' do
124
- context 'and prefetched `element` is nil' do
125
- it 'raise an error' do
126
- subject = described_class.new(options.except(:selector, :element))
127
- expect { subject.validate! }.to raise_exception(PageMagic::InvalidConfigurationException,
128
- described_class::INVALID_SELECTOR_MSG)
129
- end
130
- end
131
-
132
- context 'when `element` is not nil' do
133
- it 'does not raise an error' do
134
- subject = described_class.new(options.except(:selector))
135
- expect { subject.validate! }.not_to raise_exception
136
- end
137
- end
138
- end
139
-
140
- context 'when is empty hash' do
141
- it 'raises an error' do
142
- subject = described_class.new(options.update(selector: {}).except(:element))
143
- expect { subject.validate! }.to raise_exception(PageMagic::InvalidConfigurationException,
144
- described_class::INVALID_SELECTOR_MSG)
145
- end
146
- end
147
-
148
- context 'when defined on both class and as parameter' do
149
- it 'uses the supplied selector' do
150
- element_class = Class.new(PageMagic::Element) do
151
- selector css: 'selector'
152
- end
153
-
154
- subject = described_class.new(options.update(element_class: element_class))
155
- expect { subject.validate! }.not_to raise_exception
156
- end
157
- end
158
- end
159
-
160
163
  context 'when type nil' do
161
164
  it 'raise an error' do
162
165
  subject = described_class.new(options.except(:type))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-01 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport