49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/intermodal/rspec/models/accountability.rb', line 49
def implements_get_interface(&blk)
describe '.get' do
let(:model) { subject.class }
let(:different_account) { Account.make! }
it { model.should respond_to :get }
context ':all' do
context 'when unscoped to account' do
let(:collection) { model.get(:all) }
it 'should find all resources' do
collection.should include(resource)
collection.size.should eql(1)
end
end
context 'when scoped to account' do
let(:collection) { model.get(:all, account: account) }
it 'should find all resources' do
collection.should include(resource)
collection.size.should eql(1)
end
end
end
context 'by id' do
it 'should find resource by id' do
model.get(resource.id).should eql(resource)
end
it 'should return a writeable resource' do
model.get(resource.id).should_not be_readonly
end
end
context 'by account' do
it 'should find resource scoped to account' do
model.get(resource.id, account: account).should eql(resource)
end
it 'should find resource scoped to account id' do
model.get(resource.id, account_id: account.id).should eql(resource)
end
it 'should find a writeable resource scoped to account id' do
model.get(resource.id, account_id: account.id).should_not be_readonly
end
it 'should not find resource scoped to a different account' do
expect { model.get(resource.id, account: different_account) }.to raise_error(ActiveRecord::RecordNotFound)
end
it 'should not find resource scoped to a different account id ' do
expect { model.get(resource.id, account_id: different_account.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
instance_eval(&blk) if blk
end
end
|