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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/intermodal/rspec/models/has_parent_resource.rb', line 82
def implements_get_interface_for_nested_resource(&blk)
implements_get_interface do
context 'by parent' do
it 'should find resource scoped to parent' do
model.get(subject.id, :parent => subject.send(parent_resource_name)).should eql(subject)
end
it 'should find resource scoped to parent id' do
model.get(subject.id, :parent_id => subject.send(parent_resource_name).id).should eql(subject)
end
it 'should find writeable resource scoped to parent id' do
model.get(subject.id, :parent_id => subject.send(parent_resource_name).id).should_not be_readonly
end
end
context 'by parent and account' do
it 'should find resource scoped to account id and parent id' do
model.get(subject.id, :parent_id => subject.send(parent_resource_name).id, :account_id => account.id).should eql(subject)
end
it 'should find writeable resource scoped to account id and parent id' do
model.get(subject.id, :parent_id => subject.send(parent_resource_name).id, :account_id => account.id).should_not be_readonly
end
it 'should not find resource scoped to a different parent' do
lambda { model.get(subject.id, :parent => different_parent) }.should raise_error(ActiveRecord::RecordNotFound)
end
it 'should not find resource scoped to a different parent id' do
lambda { model.get(subject.id, :parent_id => different_parent.id) }.should raise_error(ActiveRecord::RecordNotFound)
end
it 'should not find resource scoped to a parent in a different account' do
lambda { model.get(subject.id, :parent_id => parent_with_different_account.id, :account_id => account) }.should raise_error(ActiveRecord::RecordNotFound)
end
it 'should not find resource scoped to a correct parent but incorrect account' do
lambda { model.get(subject.id, :parent_id => subject.send(parent_resource_name).id, :account_id => different_account) }.should raise_error(ActiveRecord::RecordNotFound)
end
end
instance_eval(&blk) if blk
end
end
|