action_spec.rb revision 3da1771ccd411609156bf2721537c6a8e41050d4
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumirequire 'spec_helper'
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumidescribe Action do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context '#eta' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:action) { create :action }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:target) { action.created_at + action.eta }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should return the initial eta at creation time' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi expect(action.eta(action.created_at).to_i).
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi to eq(action.initial_eta)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should return correct eta' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi expect(action.eta(target - 1).to_i).to eq(1)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should return 0 if the eta has been reached' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi expect(action.eta(target + 5.minutes)).to eq(0)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context '#status' do
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumi let(:action) { create :action, resource: resource }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:status) { 'some status' }
8900b9eb2514c07047541833286428572493a9fdStéphane Graber
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context 'on resource with state' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:resource) { mock_model("Resource", state: status) }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should return the correct status' do
faefa7f8584a7d1567df2e6f1f9240a28a6466abStéphane Graber expect(action.status).to eq(status)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context 'on resource with status' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:resource) { mock_model("Resource", status: status) }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should return the correct status' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi expect(action.status).to eq(status)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context 'on resource w/o anything' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi let(:resource) { mock_model("Resource") }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi it 'should complain with an error' do
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi expect { action.status }.to raise_error(NoMethodError)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi end
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiend
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi