BidsketchObject refactor, added sections
Dylan Montgomery
committed Jun 03, 2015
commit 544c14b1bd6b0ff02c9798e7de03670b7fe5a570
Showing 10
changed files with
36 additions
and 39 deletions
bidsketch.rb b/lib/bidsketch.rb
+1
-0
| @@ | @@ -4,6 +4,7 @@ require "bidsketch/bidsketch_object" |
| require "bidsketch/client" | |
| require "bidsketch/fee" | |
| require "bidsketch/proposal" | |
| + | require "bidsketch/section" |
| module Bidsketch | |
| class << self | |
bidsketch/bidsketch_object.rb b/lib/bidsketch/bidsketch_object.rb
+15
-0
| @@ | @@ -2,5 +2,20 @@ require 'ostruct' |
| module Bidsketch | |
| class BidsketchObject < OpenStruct | |
| + | class << self |
| + | def all |
| + | Bidsketch::API.get("#{root_path}.json").map { |object| self.new(object) } |
| + | end |
| + | |
| + | def find(id) |
| + | response = Bidsketch::API.get("#{root_path}/#{id}.json") |
| + | self.new(response) |
| + | end |
| + | |
| + | def root_path |
| + | class_name = self.to_s.gsub(/^.*::/, '').downcase |
| + | "/#{class_name}s" |
| + | end |
| + | end |
| end | |
| end | |
| \ No newline at end of file | |
bidsketch/client.rb b/lib/bidsketch/client.rb
+0
-12
| @@ | @@ -1,16 +1,4 @@ |
| module Bidsketch | |
| class Client < BidsketchObject | |
| - | class << self |
| - | def all |
| - | Bidsketch::API.get('/clients.json').map { |client| self.new(client) } |
| - | end |
| - | |
| - | def find(id) |
| - | response = Bidsketch::API.get("/clients/#{id}.json") |
| - | if response |
| - | self.new(response) |
| - | end |
| - | end |
| - | end |
| end | |
| end | |
| \ No newline at end of file | |
bidsketch/fee.rb b/lib/bidsketch/fee.rb
+0
-12
| @@ | @@ -1,16 +1,4 @@ |
| module Bidsketch | |
| class Fee < BidsketchObject | |
| - | class << self |
| - | def all |
| - | Bidsketch::API.get('/fees.json').map { |fee| self.new(fee) } |
| - | end |
| - | |
| - | def find(id) |
| - | response = Bidsketch::API.get("/fees/#{id}.json") |
| - | if response |
| - | self.new(response) |
| - | end |
| - | end |
| - | end |
| end | |
| end | |
| \ No newline at end of file | |
bidsketch/proposal.rb b/lib/bidsketch/proposal.rb
+0
-12
| @@ | @@ -1,16 +1,4 @@ |
| module Bidsketch | |
| class Proposal < BidsketchObject | |
| - | class << self |
| - | def all |
| - | Bidsketch::API.get('/proposals.json').map { |proposal| self.new(proposal) } |
| - | end |
| - | |
| - | def find(id) |
| - | response = Bidsketch::API.get("/proposals/#{id}.json") |
| - | if response |
| - | self.new(response) |
| - | end |
| - | end |
| - | end |
| end | |
| end | |
| \ No newline at end of file | |
bidsketch/section.rb b/lib/bidsketch/section.rb
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | module Bidsketch |
| + | class Section < BidsketchObject |
| + | end |
| + | end |
| \ No newline at end of file | |
spec/fee_spec.rb
+2
-1
| @@ | @@ -5,7 +5,8 @@ describe Bidsketch::Fee, vcr: true do |
| ] | |
| - | it_should_behave_like 'a findable object', 180219, [:id, :name, :url, :app_url, :created_at, :updated_at, |
| + | it_should_behave_like 'a findable object', 180219, [ |
| + | :id, :name, :url, :app_url, :created_at, :updated_at, |
| :quantity, :category, :total, :currency, :amount, :unit, | |
| :details, :feetype, :description | |
| ] | |
spec/section_spec.rb
+12
-0
| @@ | @@ -0,0 +1,12 @@ |
| + | describe Bidsketch::Section, vcr: true do |
| + | it_should_behave_like 'a listable object', Bidsketch::Section, [ |
| + | :id, :name, :url, :app_url, :created_at, :updated_at, |
| + | :category, :sectiontype |
| + | ] |
| + | |
| + | |
| + | it_should_behave_like 'a findable object', 390816, [ |
| + | :id, :name, :url, :app_url, :created_at, :updated_at, |
| + | :category, :sectiontype, :description |
| + | ] |
| + | end |
spec/shared_examples/findable.rb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| RSpec.shared_examples 'a findable object' do |id, attributes| | |
| - | let(:object) { VCR.use_cassette("#{subject.class.to_s}_id") { subject.class.find(id) } } |
| + | let(:object) { VCR.use_cassette("#{subject.class.to_s}_#{id}") { subject.class.find(id) } } |
| attributes.each do |attribute| | |
| it "should return a value for #{attribute}" do | |
spec/shared_examples/listable.rb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| RSpec.shared_examples 'a listable object' do |subject, attributes = []| | |
| - | let(:object) { VCR.use_cassette("#{subject.class.to_s}") { subject.class.all } } |
| + | let(:list) { VCR.use_cassette(subject.to_s) { subject.all } } |
| it "should return an array of objects" do | |
| expect(list.class).to eq Array | |