refactored into shared examples
Dylan Montgomery
committed Jun 03, 2015
commit 7dde4f1c64cb7d7722fef78d35cdd42dd7596209
Showing 8
changed files with
77 additions
and 60 deletions
bidsketch.rb b/lib/bidsketch.rb
+1
-0
| @@ | @@ -3,6 +3,7 @@ require "bidsketch/api" |
| require "bidsketch/bidsketch_object" | |
| require "bidsketch/client" | |
| require "bidsketch/fee" | |
| + | require "bidsketch/proposal" |
| module Bidsketch | |
| class << self | |
bidsketch/proposal.rb b/lib/bidsketch/proposal.rb
+16
-0
| @@ | @@ -0,0 +1,16 @@ |
| + | 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 | |
spec/client_spec.rb
+11
-31
| @@ | @@ -1,33 +1,13 @@ |
| - | describe Bidsketch::Client do |
| - | describe '#all' do |
| - | it 'returns all clients', vcr: true do |
| - | clients = Bidsketch::Client.all |
| - | client = clients.first |
| - | attributes = [ |
| - | :id, :first_name, :last_name, :email, :name, :phone, |
| - | :url, :app_url, :created_at, :updated_at |
| - | ] |
| + | describe Bidsketch::Client, vcr: true do |
| + | it_should_behave_like 'a listable object', Bidsketch::Client, [ |
| + | :id, :first_name, :last_name, :email, :name, :phone, |
| + | :url, :app_url, :created_at, :updated_at |
| + | ] |
| - | attributes.each do |attribute| |
| - | expect(client.respond_to?(attribute)).to be true |
| - | end |
| - | end |
| - | end |
| - | |
| - | describe '#find' do |
| - | let(:client_id) { 356834 } |
| - | it 'returns a client', vcr: true do |
| - | client = Bidsketch::Client.find(client_id) |
| - | attributes = [ |
| - | :id, :first_name, :last_name, :email, :name, :phone, :alt_phone, |
| - | :website, :address_field_one, :address_field_two, :city, :state, |
| - | :postal_zip, :country, :notes, :other_contact, :url, :app_url, |
| - | :created_at, :updated_at |
| - | ] |
| - | |
| - | attributes.each do |attribute| |
| - | expect(client.respond_to?(attribute)).to be true |
| - | end |
| - | end |
| - | end |
| + | it_should_behave_like 'a findable object', 356834, [ |
| + | :id, :first_name, :last_name, :email, :name, :phone, :alt_phone, |
| + | :website, :address_field_one, :address_field_two, :city, :state, |
| + | :postal_zip, :country, :notes, :other_contact, :url, :app_url, |
| + | :created_at, :updated_at |
| + | ] |
| end | |
spec/fee_spec.rb
+9
-29
| @@ | @@ -1,32 +1,12 @@ |
| - | describe Bidsketch::Fee do |
| - | describe '#all' do |
| - | it 'returns all clients', vcr: true do |
| - | fees = Bidsketch::Fee.all |
| - | fee = fees.first |
| - | attributes = [ |
| - | :id, :name, :url, :app_url, :created_at, :updated_at, |
| - | :category, :total, :feetype, :details |
| - | ] |
| + | describe Bidsketch::Fee, vcr: true do |
| + | it_should_behave_like 'a listable object', Bidsketch::Fee, [ |
| + | :id, :name, :url, :app_url, :created_at, :updated_at, |
| + | :category, :total, :feetype, :details |
| + | ] |
| - | attributes.each do |attribute| |
| - | expect(fee.respond_to?(attribute)).to be true |
| - | end |
| - | end |
| - | end |
| - | describe '#find' do |
| - | let(:fee_id) { 180219 } |
| - | it 'returns a client', vcr: true do |
| - | fee = Bidsketch::Fee.find(fee_id) |
| - | attributes = [ |
| - | :id, :name, :url, :app_url, :created_at, :updated_at, |
| - | :quantity, :category, :total, :currency, :amount, :unit, |
| - | :details, :feetype, :description |
| - | ] |
| - | |
| - | attributes.each do |attribute| |
| - | expect(fee.respond_to?(attribute)).to be true |
| - | end |
| - | end |
| - | end |
| + | 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 |
| + | ] |
| end | |
spec/proposal_spec.rb
+14
-0
| @@ | @@ -0,0 +1,14 @@ |
| + | describe Bidsketch::Proposal, vcr: true do |
| + | it_should_behave_like 'a listable object', Bidsketch::Proposal, [ |
| + | :id, :url, :app_url, :created_at, :updated_at, |
| + | :name, :description, :status, :is_draft |
| + | ] |
| + | |
| + | it_should_behave_like 'a findable object', 189362, [ |
| + | :id, :url, :app_url, :created_at, :updated_at, |
| + | :proposal_date, :name, :description, :status, |
| + | :is_draft, :user, :currency, :tax, :tax2, :monthly_fees, |
| + | :yearly_fees, :one_time_fees, :discount, :total, |
| + | :settings, :client, :content |
| + | ] |
| + | end |
spec/shared_examples/findable.rb
+9
-0
| @@ | @@ -0,0 +1,9 @@ |
| + | RSpec.shared_examples 'a findable object' do |id, attributes| |
| + | 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 |
| + | expect(object.respond_to?(attribute)).to be true |
| + | end |
| + | end |
| + | end |
spec/shared_examples/listable.rb
+14
-0
| @@ | @@ -0,0 +1,14 @@ |
| + | RSpec.shared_examples 'a listable object' do |subject, attributes = []| |
| + | let(:object) { VCR.use_cassette("#{subject.class.to_s}") { subject.class.all } } |
| + | |
| + | it "should return an array of objects" do |
| + | expect(list.class).to eq Array |
| + | expect(list.first.class).to eq subject |
| + | end |
| + | |
| + | attributes.each do |attribute| |
| + | it "should return a value for #{attribute}" do |
| + | expect(list.first.respond_to?(attribute)).to be true |
| + | end |
| + | end |
| + | end |
spec/spec_helper.rb
+3
-0
| @@ | @@ -4,6 +4,9 @@ require 'dotenv' |
| Dotenv.load | |
| + | # Load shared examples |
| + | Dir['./spec/shared_examples/**/*.rb'].sort.each { |f| require f } |
| + | |
| # This file was generated by the `rspec --init` command. Conventionally, all | |
| # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. | |
| # The generated `.rspec` file contains `--require spec_helper` which will cause | |