spec/model/base_spec.rb in yammer-client-0.1.2 vs spec/model/base_spec.rb in yammer-client-0.1.3
- old
+ new
@@ -1,18 +1,29 @@
require File.expand_path('../../spec_helper', __FILE__)
describe Yammer::Base do
+
class DummyModel < Yammer::Base
attr_accessor_deffered :first_name, :last_name
end
class Yammer::Client
def update_dummy_model(id, opts={})
put("/api/v1/dummy_models/#{id}", opts)
end
end
+ before :all do
+ Yammer.configure do |conf|
+ conf.access_token = 'TolNOFka9Uls2DxahNi78A'
+ end
+ end
+
+ after :all do
+ Yammer.reset!
+ end
+
context 'new user object with id' do
subject { DummyModel.new(:id => 42) }
describe "#id" do
@@ -21,12 +32,12 @@
end
end
describe "#id=" do
it 'sets id' do
- # subject.send(:id, 2)
- # expect(subject.id).to eq 2
+ subject.send(:"id=", 2)
+ expect(subject.id).to eq 2
end
end
describe "#new_record?" do
it 'returns false' do
@@ -106,48 +117,58 @@
subject
end
end
describe "#save" do
+
context 'unmodified model' do
it 'does nothing' do
expect(subject.save).to eq subject
end
end
context 'modified model' do
subject { DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters') }
it 'should update model' do
- Yammer.should_receive(:update_dummy_model).with(42, hash_including(
+ api_handler = double("ApiHandler")
+ api_handler.should_receive(:update_dummy_model).with(42, hash_including(
:first_name =>'john',
:last_name => 'smith')
).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
+
+ subject.stub(:api_handler).and_return(api_handler)
subject.first_name = 'john'
subject.last_name = 'smith'
subject.save
end
end
context 'unmodified new model' do
subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
it 'should do nothing' do
- Yammer.should_receive(:create_dummy_model).with(
+ api_handler = double("ApiHandler")
+ api_handler.should_receive(:create_dummy_model).with(
hash_including(:first_name =>'jim', :last_name => 'peters')
).and_return(double('Response', :success? => true, :created? => true, :body => {:id => '2'}))
+
+ subject.stub(:api_handler).and_return(api_handler)
subject.save
end
end
context 'modified new model' do
subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
it 'should create model' do
- Yammer.should_receive(:create_dummy_model).with({
+ api_handler = double("ApiHandler")
+ api_handler.should_receive(:create_dummy_model).with({
:first_name =>'john',
:last_name => 'peters'
}).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
+
+ subject.stub(:api_handler).and_return(api_handler)
subject.first_name = 'john'
subject.save
end
end
end
\ No newline at end of file