spec/acfs/resource/query_methods_spec.rb in acfs-1.0.0.dev.1.b305 vs spec/acfs/resource/query_methods_spec.rb in acfs-1.0.0

- old
+ new

@@ -12,11 +12,11 @@ stub_request(:get, 'http://users.example.org/users/2') .to_return response id: 2, type: 'Customer', name: 'Clare Customer', age: 24 end - let(:action) { lambda{|cb = nil| model.find(1, &cb) } } + let(:action) { ->(cb = nil) { model.find(1, &cb) } } it_behaves_like 'a query method with multi-callback support' it 'should load a single remote resource' do user = action.call Acfs.run @@ -42,11 +42,11 @@ end context 'with 404 response' do before do stub_request(:get, 'http://users.example.org/users/1') - .to_return response({error: 'not found'}, status: 404) + .to_return response({error: 'not found'}, {status: 404}) end it 'should raise a NotFound error' do @user = model.find 1 @@ -93,11 +93,11 @@ expect(users[0].attributes).to eq id: 1, name: 'Anon', age: 12 expect(users[1].attributes).to eq id: 2, name: 'Johnny', age: 42 end it 'should invoke callback after all models are loaded' do - block = proc{} + block = proc {} expect(block).to receive(:call) do |users| expect(users).to equal @users expect(users.size).to be == 2 expect(users).to be_loaded end @@ -105,12 +105,12 @@ @users = model.find([1, 2], &block) Acfs.run end it 'should invoke multiple callback after all models are loaded' do - proc1 = proc{} - proc2 = proc{} + proc1 = proc {} + proc2 = proc {} expect(proc1).to receive(:call) do |users| expect(users).to equal @users expect(users.size).to be == 2 expect(users).to be_loaded end @@ -135,11 +135,11 @@ end context 'with one 404 response' do before do stub_request(:get, 'http://users.example.org/users/1') - .to_return response({error: 'not found'}, status: 404) + .to_return response({error: 'not found'}, {status: 404}) end it 'should raise resource not found error' do model.find [1, 2] @@ -160,12 +160,12 @@ {id: 2, type: 'Computer'}, {id: 3, type: 'Mac'}] end it 'should invoke multiple callback after all models are loaded' do - proc1 = proc{} - proc2 = proc{} + proc1 = proc {} + proc2 = proc {} expect(proc1).to receive(:call) do |computers| expect(computers).to equal @computers expect(computers.size).to be == 3 expect(computers).to be_loaded end @@ -272,11 +272,11 @@ {id: 4, type: 'Maria', age: 24}, {id: 7, type: 'James', age: 24}] end it 'should invoke callback after model is loaded' do - block = proc{} + block = proc {} expect(block).to receive(:call) do |user| expect(user).to eql @user.__getobj__ expect(user).to be_a MyUser expect(user).to be_loaded @@ -285,12 +285,12 @@ @user = model.send described_method, age: 24, &block Acfs.run end it 'should invoke multiple callbacks after model is loaded' do - proc1 = proc{} - proc2 = proc{} + proc1 = proc {} + proc2 = proc {} expect(proc1).to receive(:call) do |user| expect(user).to eql @user.__getobj__ expect(user).to be_a MyUser expect(user).to be_loaded @@ -338,11 +338,11 @@ end it { should be_nil } it 'should invoke callback after model is loaded' do - block = proc{} + block = proc {} expect(block).to receive(:call) do |user| expect(user).to eql @user.__getobj__ expect(user).to be_a NilClass end @@ -350,12 +350,12 @@ @user = model.find_by age: 24, &block Acfs.run end it 'should invoke multiple callbacks after model is loaded' do - proc1 = proc{} - proc2 = proc{} + proc1 = proc {} + proc2 = proc {} expect(proc1).to receive(:call) do |user| expect(user).to eql @user.__getobj__ expect(user).to be_a NilClass end @@ -391,11 +391,11 @@ model.find_by! age: 24 expect { Acfs.run }.to raise_error Acfs::ResourceNotFound end it 'should not invoke callback after model could not be loaded' do - block = proc{} + block = proc {} expect(block).not_to receive(:call) model.find_by! age: 24, &block expect { Acfs.run }.to raise_error @@ -404,34 +404,34 @@ end describe '#each_page' do context 'without parameters' do before do - stub_request(:get, 'http://users.example.org/users'). - to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=2>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=2'). - to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=3>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=3'). - to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=4>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=4'). - to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '' - }) + stub_request(:get, 'http://users.example.org/users') + .to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=2>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=2') + .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=3>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=3') + .to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=4>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=4') + .to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '' + }) end it 'should iterate all pages' do index = 0 model.each_page do |page| @@ -446,34 +446,34 @@ end end context 'with parameters' do before do - stub_request(:get, 'http://users.example.org/users?param=bla'). - to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?where=fuu&page=2'). - to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=3>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=3'). - to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=4>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=4'). - to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '' - }) + stub_request(:get, 'http://users.example.org/users?param=bla') + .to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?where=fuu&page=2') + .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=3>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=3') + .to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=4>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=4') + .to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '' + }) end it 'should call first page with params and follow relations' do index = 0 model.each_page(param: 'bla') do |page| @@ -490,33 +490,33 @@ end describe '#each_item' do context 'without parameters' do before do - stub_request(:get, 'http://users.example.org/users'). - to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=2>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=2'). - to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=3>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=3'). - to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'},{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '<http://users.example.org/users?page=4>; rel="next"' - }) - stub_request(:get, 'http://users.example.org/users?page=4'). - to_return response([{id: 5, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], - headers: { - 'X-Total-Pages' => '4', - 'Link' => '' - }) + stub_request(:get, 'http://users.example.org/users') + .to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=2>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=2') + .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=3>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=3') + .to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}, {id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '<http://users.example.org/users?page=4>; rel="next"' + }) + stub_request(:get, 'http://users.example.org/users?page=4') + .to_return response([{id: 5, name: 'Anno', age: 1604, born_at: 'Santa Maria'}], + headers: { + 'X-Total-Pages' => '4', + 'Link' => '' + }) end it 'should iterate all pages' do indecies = [] model.each_item do |item|