conduit 1.0.4 → 1.1.0

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
  SHA1:
3
- metadata.gz: 3bb1b8f51e94f9a01e34b93b204ddcc665f0fa97
4
- data.tar.gz: 83f0645c72bea202ad14ee8feda10aeb2a343847
3
+ metadata.gz: b37e7362d4af2ed4841798aff5b04f2285cce7eb
4
+ data.tar.gz: 99da695bd5abdb9233a3957482741ea9b05dc1fd
5
5
  SHA512:
6
- metadata.gz: 017b4f44d22ef1b74dd5d032ca1a8f52978e4e27abf59e730144d6a818891425613433b3a8e360174d7e06dbd4c4dfed0568b92a0a4fa7ce479136f474d47835
7
- data.tar.gz: 41918d02a479a3fc530ca6061dc54d2982543f37cf7ac43b79ea4e43f5fdc64f48eb8fd9ad5f375f92dc70d6883c10480fe739742fa9849a6372345d7119cb3a
6
+ metadata.gz: 37d02a757f479664b1eac37eff9e07e45c7b4ef254b5311e96961818f2d5f663e545508ca10cd1e001e8eb706b9bbba3dc5a689f2f477ca43944a1f17d187659
7
+ data.tar.gz: 84b2e662f55f271a1aad27044ff3ea14379de08014faa24cb15a637ff1ffcedadaddfdc7b6e2a29bfe121276fbf79850d57866145dde2c0e35ed0b8d510a4a75
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # e.g.
6
6
  # => class MyAction < Conduit::Core::Action
7
- # => required_attributes :foo, :bar
7
+ # => required_attributes :foo, :bar, [:either, :or]
8
8
  # => optional_attributes :baz
9
9
  # => end
10
10
  #
@@ -107,7 +107,7 @@ module Conduit
107
107
  # will default to `nil`.
108
108
  #
109
109
  def attributes_with_values
110
- attributes.inject({}) do |hash, attribute|
110
+ attributes.to_a.flatten.inject({}) do |hash, attribute|
111
111
  hash.tap do |h|
112
112
  h[attribute] = @options[attribute]
113
113
  end
@@ -168,6 +168,8 @@ module Conduit
168
168
  #
169
169
  def validate!(options)
170
170
  missing_keys = (requirements.to_a - options.keys)
171
+ either_keys = requirements.select { |key| key.is_a?(Array) }
172
+ missing_keys.reject! { |key| either_keys.any? { |either| (either & options.keys).present? }}
171
173
  if missing_keys.any?
172
174
  raise ArgumentError,
173
175
  "Missing keys: #{missing_keys.join(', ')}"
@@ -1,3 +1,3 @@
1
1
  module Conduit
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -17,26 +17,41 @@ shared_examples_for Conduit::Core::Action do
17
17
 
18
18
  describe '.requirements' do
19
19
  it 'returns an array of required attributes' do
20
- subject.class.requirements.should == [:foo, :bar, :baz].to_set
20
+ subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
21
21
  end
22
22
  end
23
23
 
24
24
  describe '.attributes' do
25
25
  it 'returns an array of known attributes' do
26
- subject.class.requirements.should == [:foo, :bar, :baz].to_set
26
+ subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ context "action has an array in its required_attibutes field" do
32
+ let(:attrs) { request_attributes }
33
+ it "raises an error if missing both of the keys" do
34
+ attrs.delete(:either)
35
+ attrs.delete(:or)
36
+ lambda { described_class.new(attrs) }.should raise_error(ArgumentError)
37
+ end
38
+
39
+ it "doesn't raise an error if only one key is missing" do
40
+ attrs.delete(:either)
41
+ attrs[:or] = "value of or"
42
+ lambda { described_class.new(attrs) }.should_not raise_error
43
+ end
44
+ end
45
+
31
46
  context 'with an instance' do
32
47
  describe '#attributes_with_values' do
33
48
  context 'with optional attribute not set' do
34
- let (:attrs) { request_attributes.merge(buz: nil) }
49
+ let (:attrs) { request_attributes.merge(buz: nil, or: nil) }
35
50
  its(:attributes_with_values) { should eq(attrs) }
36
51
  end
37
52
 
38
53
  context 'with optional attribute set' do
39
- let (:attrs) { request_attributes.merge(buz: "value for buz") }
54
+ let (:attrs) { request_attributes.merge(buz: "value for buz", or: nil) }
40
55
  subject { described_class.new(attrs) }
41
56
  its(:attributes_with_values) { should eq(attrs) }
42
57
  end
@@ -2,9 +2,10 @@ module Helper
2
2
 
3
3
  def request_attributes
4
4
  {
5
- foo: 'value for foo',
6
- bar: 'value for bar',
7
- baz: 'value for baz'
5
+ foo: "value for foo",
6
+ bar: "value for bar",
7
+ baz: "value for baz",
8
+ either: "value for either"
8
9
  }
9
10
  end
10
11
 
@@ -3,7 +3,7 @@ module Conduit::Driver::MyDriver
3
3
 
4
4
  remote_url 'http://foo.com/api.xml'
5
5
 
6
- required_attributes :foo, :bar, :baz
6
+ required_attributes :foo, :bar, :baz, [:either, :or]
7
7
  optional_attributes :buz
8
8
 
9
9
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conduit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kelley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.2.2
240
+ rubygems_version: 2.6.7
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Conduit is an interface for debit platforms.
@@ -262,3 +262,4 @@ test_files:
262
262
  - spec/support/xml/xml_modified_request.xml
263
263
  - spec/support/xml/xml_request.xml
264
264
  - spec/support/xml/xml_response.xml
265
+ has_rdoc: