Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Add AssignmentCollection#current #24

Merged
merged 3 commits into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/nacre/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class Connection

attr_accessor :response, :errors

def initialize(args = {})
def initialize(
user_id: Nacre.configuration.user_id,
email: Nacre.configuration.email,
password: Nacre.configuration.password
)
self.errors = []
initialize_link
authenticate!
Expand Down
4 changes: 4 additions & 0 deletions lib/nacre/order/assignment_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module Nacre
class Order::AssignmentCollection < AbstractCollection

def current
members.select { |assignment| assignment.key == :current }.first
end

def self.resource_class
Nacre::Order::Assignment
end
Expand Down
2 changes: 1 addition & 1 deletion nacre.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "webmock"
spec.add_development_dependency "dotenv"
Expand Down
27 changes: 9 additions & 18 deletions spec/lib/nacre/abstract_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
describe Nacre::AbstractResource do

describe 'initialization' do
it 'should create attributes from the params' do
pending
xit 'should create attributes from the params' do
end
end

Expand All @@ -17,48 +16,40 @@
end

describe '.attribute' do
it 'should create an accessor' do
pending
xit 'should create an accessor' do
end

it 'should add the attribute to the fields list' do
pending
xit 'should add the attribute to the fields list' do
end
end

describe '.fields' do
it 'should be a list of attribute symbols' do
pending
xit 'should be a list of attribute symbols' do
end
end

describe '#attributes=' do
it 'should set the attributes only for existing fields' do
pending
xit 'should set the attributes only for existing fields' do
end

it 'should ignore attributes for non-existent fields' do
pending
xit 'should ignore attributes for non-existent fields' do
end
end

describe '.from_json' do
context "when it's a real response" do
it 'returns a new object with the params from json' do
pending
xit 'returns a new object with the params from json' do
end
end

context "when it's an error (outside of a response structure)" do
it 'adds the unstructured error to the connection errors' do
pending
xit 'adds the unstructured error to the connection errors' do
end
end
end

describe '.errors' do
it 'returns the errors from the connection' do
pending
xit 'returns the errors from the connection' do
end
end
end
6 changes: 6 additions & 0 deletions spec/lib/nacre/order/assignment_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
it 'should be a collection of Order::AssignmentDetails' do
expect(subject.first).to be_a(Nacre::Order::Assignment)
end

describe '#current' do
it 'should returnt the current assignment' do
expect(subject.current.key).to eq(:current)
end
end
end
1 change: 0 additions & 1 deletion spec/lib/nacre/order/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

it 'should have an assignment key' do
expect(subject.key).to eq('current')

end

it 'should have a channel ID' do
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/nacre/product_price_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ def make_resource_request(url, fixture_file_name)

describe '.errors' do
context 'when there are errors' do
it 'should return a list of errors' do
pending
xit 'should return a list of errors' do
end
end

context 'when there are no errors' do
it 'should return an empty list' do
pending
xit 'should return an empty list' do
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/nacre/request_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@
expect(subject.pagination).to eq(['firstResult=1', 'pageSize=500'])
end

it 'should raise an error when the fields are missing' do
pending 'This class should have validations'
xit 'should raise an error when the fields are missing' do
end
end
end
12 changes: 6 additions & 6 deletions spec/support/boolean_attributes_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
shared_examples_for 'a boolean attribute' do

context 'when using the default params' do
it 'should be false' do
it 'should be false' do |example|
expect(subject.send("#{example.metadata[:method_name]}")).to eq(false)
end
end

it 'should be true when it is set to true' do
it 'should be true when it is set to true' do |example|
subject.send("#{example.metadata[:method_name]}=",true)
expect(subject.send("#{example.metadata[:method_name]}")).to eq(true)
end

it 'should be true when it is set to "true"' do
it 'should be true when it is set to "true"' do |example|
subject.send("#{example.metadata[:method_name]}=",'true')
expect(subject.send("#{example.metadata[:method_name]}")).to eq(true)
end

it 'should be false when it is set to false' do
it 'should be false when it is set to false' do |example|
subject.send("#{example.metadata[:method_name]}=",false)
expect(subject.send("#{example.metadata[:method_name]}")).to eq(false)
end

it 'should be false when it is set to "false"' do
it 'should be false when it is set to "false"' do |example|
subject.send("#{example.metadata[:method_name]}=",'false')
expect(subject.send("#{example.metadata[:method_name]}")).to eq(false)
end

['1',1,nil,'::','foo'].each do |value|
it "should be false when set to #{value.to_s}" do
it "should be false when set to #{value.to_s}" do |example|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant use of Object#to_s in interpolation.

subject.send("#{example.metadata[:method_name]}=",value)
expect(subject.send("#{example.metadata[:method_name]}")).to eq(false)
end
Expand Down