biller_bot_resource 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -0
- data/biller_bot_resource.gemspec +2 -3
- data/lib/biller_bot_resource.rb +2 -0
- data/lib/biller_bot_resource/product.rb +33 -0
- data/lib/biller_bot_resource/version.rb +1 -1
- data/spec/lib/biller_bot_resource/product_context_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -0
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a99fdcc82deaf4fe33e71de9b3aec0bb5ea116
|
4
|
+
data.tar.gz: e5643dee62d2ee1414d33b2d715bb4b66f68ba68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f5295b254d889e4fc7547a664d01d674e4257dde70cf71e72e32d9cb4ea5591ae3619f50a927c53d2151fdb27938a21f3c9de775dd87f8963a1b2d3cab8a3bd
|
7
|
+
data.tar.gz: 4b971651e7b962c6e7d3af252f7caf85bb7b0432d4f4ff5552a791b8846d20753f2b4c8e4c7237133f99bb41d01ed89e9075039f3d032317defcfcc60c771bfc
|
data/Rakefile
CHANGED
data/biller_bot_resource.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
21
|
+
s.add_dependency "activeresource", "~> 3.2.0"
|
22
|
+
s.add_development_dependency "rspec"
|
24
23
|
end
|
data/lib/biller_bot_resource.rb
CHANGED
@@ -15,6 +15,29 @@ class BillerBotResource::Product < BillerBotResource::Resource
|
|
15
15
|
# saved independently.
|
16
16
|
def force_persisted
|
17
17
|
@persisted = true
|
18
|
+
|
19
|
+
# Propogate to all children too.
|
20
|
+
contexts.each do |c|
|
21
|
+
c.product_id = product_id
|
22
|
+
c.force_persisted
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Fetch all the children contexts with the given context type.
|
28
|
+
#
|
29
|
+
# @param [String] type The type of context to be searching for
|
30
|
+
# @return [Array<BillerBotResource::Product::Context] The matching contexts
|
31
|
+
def children_with_type(type)
|
32
|
+
matches = contexts.select { |c| (c.type.downcase == type.to_s.downcase) }
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Fetch all the child contexts in a flat structure. Also include myself.
|
37
|
+
#
|
38
|
+
# @return [Array<BillerBotResource::Product::Context>]
|
39
|
+
def descendants_with_self
|
40
|
+
[self, contexts.map(&:descendants_with_self)].flatten.uniq
|
18
41
|
end
|
19
42
|
end
|
20
43
|
|
@@ -31,6 +54,16 @@ class BillerBotResource::Product < BillerBotResource::Resource
|
|
31
54
|
@attributes[:contexts]
|
32
55
|
end
|
33
56
|
|
57
|
+
def all_contexts
|
58
|
+
contexts.map(&:descendants_with_self).flatten
|
59
|
+
end
|
60
|
+
|
61
|
+
def context(id)
|
62
|
+
context = all_contexts.select { |c| c.id.try(:to_i) == id.try(:to_i) }.first
|
63
|
+
raise ActiveResource::ResourceNotFound.new(nil) if context.nil?
|
64
|
+
context
|
65
|
+
end
|
66
|
+
|
34
67
|
##
|
35
68
|
# Fetch the root product context for the given account ID.
|
36
69
|
#
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BillerBotResource::Product::Context do
|
4
|
+
let(:context) { BillerBotResource::Product::Context.new(:type => "TimeProductContext", :unit_price => 1.01, :contexts => []) }
|
5
|
+
|
6
|
+
describe :children_with_type do
|
7
|
+
it "returns an empty array when there are no children" do
|
8
|
+
context.children_with_type("SomeTestType").should be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
context "with children" do
|
12
|
+
before :each do
|
13
|
+
context.contexts << BillerBotResource::Product::Context.new(:type => "TimeProductContext", :unit_price => 1.01, :contexts => [])
|
14
|
+
context.contexts.length.should == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an empty array when there are no matches" do
|
18
|
+
context.children_with_type("SomeTestType").should be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a single result" do
|
22
|
+
context.children_with_type(context.contexts.first.type).length.should == 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns multiple results" do
|
26
|
+
context.contexts << BillerBotResource::Product::Context.new(:type => context.contexts.first.type)
|
27
|
+
context.children_with_type(context.contexts.first.type).length.should == context.contexts.length
|
28
|
+
end
|
29
|
+
|
30
|
+
it "is not case sensitive" do
|
31
|
+
context.children_with_type(context.contexts.first.type.downcase).length.should == 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require "biller_bot_resource"
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = "random"
|
19
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biller_bot_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Seefeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
12
|
-
dependencies:
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeresource
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Provides a set of Ruby classes for interacting with the BillerBot API
|
14
42
|
email:
|
15
43
|
- support@dispatchbot.com
|
@@ -31,6 +59,8 @@ files:
|
|
31
59
|
- lib/biller_bot_resource/product.rb
|
32
60
|
- lib/biller_bot_resource/resource.rb
|
33
61
|
- lib/biller_bot_resource/version.rb
|
62
|
+
- spec/lib/biller_bot_resource/product_context_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
34
64
|
homepage: https://github.com/bradseefeld/biller_bot_resource
|
35
65
|
licenses: []
|
36
66
|
metadata: {}
|
@@ -54,4 +84,6 @@ rubygems_version: 2.1.11
|
|
54
84
|
signing_key:
|
55
85
|
specification_version: 4
|
56
86
|
summary: Common resources for the BillerBot API
|
57
|
-
test_files:
|
87
|
+
test_files:
|
88
|
+
- spec/lib/biller_bot_resource/product_context_spec.rb
|
89
|
+
- spec/spec_helper.rb
|