spec/acfs_spec.rb in acfs-1.0.0.dev.1.b305 vs spec/acfs_spec.rb in acfs-1.0.0
- old
+ new
@@ -1,42 +1,41 @@
require 'spec_helper'
describe 'Acfs' do
-
before do
- stub_request(:get, 'http://users.example.org/users').to_return response([{ id: 1, name: 'Anon', age: 12 }, { id: 2, name: 'John', age: 26 }])
- stub_request(:get, 'http://users.example.org/users/2').to_return response({ id: 2, name: 'John', age: 26 })
- stub_request(:get, 'http://users.example.org/users/3').to_return response({ id: 3, name: 'Miraculix', age: 122 })
- stub_request(:get, 'http://users.example.org/users/100').to_return response({ id:100, name: 'Jimmy', age: 45 })
- stub_request(:get, 'http://users.example.org/users/2/friends').to_return response([{ id: 1, name: 'Anon', age: 12 }])
- stub_request(:get, 'http://comments.example.org/comments?user=2').to_return response([{ id: 1, text: 'Comment #1' }, { id: 2, text: 'Comment #2' }])
+ stub_request(:get, 'http://users.example.org/users').to_return response([{id: 1, name: 'Anon', age: 12}, {id: 2, name: 'John', age: 26}])
+ stub_request(:get, 'http://users.example.org/users/2').to_return response(id: 2, name: 'John', age: 26)
+ stub_request(:get, 'http://users.example.org/users/3').to_return response(id: 3, name: 'Miraculix', age: 122)
+ stub_request(:get, 'http://users.example.org/users/100').to_return response(id: 100, name: 'Jimmy', age: 45)
+ stub_request(:get, 'http://users.example.org/users/2/friends').to_return response([{id: 1, name: 'Anon', age: 12}])
+ stub_request(:get, 'http://comments.example.org/comments?user=2').to_return response([{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}])
end
it 'should update single resource synchronously' do
stub = stub_request(:put, 'http://users.example.org/users/2')
- .to_return { |request| { body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
+ .to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
@user = MyUser.find 2
Acfs.run
expect(@user).to_not be_changed
expect(@user).to be_persisted
@user.name = 'Johnny'
expect(@user).to be_changed
- expect(@user).to_not be_persisted
+ expect(@user).to be_persisted
@user.save
expect(stub).to have_been_requested
expect(@user).to_not be_changed
expect(@user).to be_persisted
end
it 'should create a single resource synchronously' do
- stub = stub_request(:post, 'http://users.example.org/sessions').to_return response({id: 'sessionhash', user: 1})
+ stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(id: 'sessionhash', user: 1)
session = Session.create ident: 'Anon'
expect(stub).to have_been_requested
expect(session.id).to be == 'sessionhash'
@@ -56,15 +55,15 @@
expect(@user.age).to be == 26
end
describe 'singleton' do
before do
- stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response({ score: 250, user_id: 5 })
+ stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(score: 250, user_id: 5)
end
it 'should create a singleton resource' do
- stub = stub_request(:post, 'http://users.example.org/singles').to_return response({ score: 250, user_id: 5 })
+ stub = stub_request(:post, 'http://users.example.org/singles').to_return response(score: 250, user_id: 5)
@single = Single.new user_id: 5, score: 250
expect(@single.new?).to eq true
@single.save
@@ -81,14 +80,16 @@
expect(@single.score).to eq 250
end
it 'should update singleton resource' do
- stub = stub_request(:put, 'http://users.example.org/singles').to_return { |request| {
+ stub = stub_request(:put, 'http://users.example.org/singles').to_return do |request|
+ {
body: request.body,
- headers: { 'Content-Type' => request.headers['Content-Type'] }
- } }
+ headers: {'Content-Type' => request.headers['Content-Type']}
+ }
+ end
@single = Single.find user_id: 5
Acfs.run
expect(@single.score).to eq 250
@@ -100,14 +101,16 @@
expect(@single.score).to eq 300
end
it 'should delete singleton resource' do
- stub = stub_request(:delete, 'http://users.example.org/singles').to_return { |request| {
+ stub = stub_request(:delete, 'http://users.example.org/singles').to_return do |request|
+ {
body: request.body,
- headers: { 'Content-Type' => request.headers['Content-Type'] }
- } }
+ headers: {'Content-Type' => request.headers['Content-Type']}
+ }
+ end
@single = Single.find user_id: 5
Acfs.run
expect(@single.new?).to eq false
@@ -116,10 +119,10 @@
expect(stub).to have_been_requested
end
it 'should raise error when calling `all\'' do
- expect{ Single.all }.to raise_error ::Acfs::UnsupportedOperation
+ expect { Single.all }.to raise_error ::Acfs::UnsupportedOperation
end
end
it 'should load multiple single resources' do
@users = MyUser.find([2, 3, 100]) do |users|