spec/acfs_spec.rb in acfs-0.25.0.1.b232 vs spec/acfs_spec.rb in acfs-0.26.0

- old
+ new

@@ -54,9 +54,75 @@ expect(@user.id).to be == 2 expect(@user.name).to be == 'John' 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 }) + 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 }) + + @single = Single.new user_id: 5, score: 250 + expect(@single.new?).to eq true + + @single.save + expect(stub).to have_been_requested + + expect(@single.new?).to eq false + expect(@single.user_id).to eq 5 + expect(@single.score).to eq 250 + end + + it 'should load singleton resource' do + @single = Single.find user_id: 5 + Acfs.run + + 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| { + body: request.body, + headers: { 'Content-Type' => request.headers['Content-Type'] } + } } + + @single = Single.find user_id: 5 + Acfs.run + + expect(@single.score).to eq 250 + + @single.score = 300 + @single.save + + expect(stub).to have_been_requested + + 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| { + body: request.body, + headers: { 'Content-Type' => request.headers['Content-Type'] } + } } + + @single = Single.find user_id: 5 + Acfs.run + + expect(@single.new?).to eq false + + @single.delete + + expect(stub).to have_been_requested + end + + it 'should raise error when calling `all\'' do + expect {Single.all}.to raise_error(NoMethodError) + end + end + it 'should load multiple single resources' do @users = MyUser.find(2, 3, 100) do |users| # This block should be called only after *all* resources are loaded. @john = users[0] @mirx = users[1]