spec/acfs/stub_spec.rb in acfs-0.43.0 vs spec/acfs/stub_spec.rb in acfs-0.43.1
- old
+ new
@@ -263,6 +263,75 @@
@user = MyUser.find 2
expect { Acfs.run }.to raise_error(Acfs::RealRequestsNotAllowedError)
end
end
end
+
+ describe 'accept?' do
+ subject { stub.accept?(op) }
+
+ context 'with a match in params' do
+ let(:op) do
+ double('operation').tap do |op|
+ allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
+ allow(op).to receive(:data).and_return({})
+ end
+ end
+
+ let(:stub) { Acfs::Stub.resource MyUser, :read, with: {id: 1337} }
+
+ it { is_expected.to be true }
+ end
+
+ context 'with a match in data' do
+ let(:op) do
+ double('operation').tap do |op|
+ allow(op).to receive(:full_params).and_return({})
+ allow(op).to receive(:data).and_return(id: 1337, blub: 'abc')
+ end
+ end
+
+ let(:stub) { Acfs::Stub.resource MyUser, :read, with: {id: 1337} }
+
+ it { is_expected.to be true }
+ end
+
+ context 'with no match in params nor data' do
+ let(:op) do
+ double('operation').tap do |op|
+ allow(op).to receive(:full_params).and_return(id: 1337)
+ allow(op).to receive(:data).and_return({})
+ end
+ end
+
+ let(:stub) { Acfs::Stub.resource MyUser, :read, with: {abc: '123'} }
+
+ it { is_expected.to be false }
+ end
+
+ context 'with a wrong match' do
+ let(:op) do
+ double('operation').tap do |op|
+ allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
+ allow(op).to receive(:data).and_return({})
+ end
+ end
+
+ let(:stub) { Acfs::Stub.resource MyUser, :read, with: {id: 1337, blub: '123'} }
+
+ it { is_expected.to be false }
+ end
+
+ context 'with a missing match' do
+ let(:op) do
+ double('operation').tap do |op|
+ allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
+ allow(op).to receive(:data).and_return({})
+ end
+ end
+
+ let(:stub) { Acfs::Stub.resource MyUser, :read, with: {id: 1337, answer: 42} }
+
+ it { is_expected.to be false }
+ end
+ end
end