|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | | -RSpec.describe Userlist::Push::Operations::Create do |
| 3 | +RSpec.describe Userlist::Push::Operations::Push do |
4 | 4 | let(:resource_type) { Userlist::Push::User } |
5 | 5 | let(:relation) { Userlist::Push::Relation.new(scope, resource_type, [described_class]) } |
6 | 6 | let(:scope) { Userlist::Push.new(push_strategy: strategy) } |
|
17 | 17 | } |
18 | 18 | end |
19 | 19 |
|
20 | | - describe '.create' do |
| 20 | + describe '.push' do |
21 | 21 | before do |
22 | 22 | allow(strategy).to receive(:call) |
23 | 23 | end |
24 | 24 |
|
25 | 25 | it 'should create a new instance of the resource_type' do |
26 | 26 | expect(resource_type).to receive(:new).with(payload, scope.config).and_return(resource) |
27 | | - relation.create(payload) |
| 27 | + relation.push(payload) |
28 | 28 | end |
29 | 29 |
|
30 | 30 | it 'should be aliased as #push' do |
31 | | - expect(relation.method(:push)).to eq(relation.method(:create)) |
| 31 | + expect(relation.method(:push)).to eq(relation.method(:push)) |
32 | 32 | end |
33 | 33 |
|
34 | 34 | context 'when given a payload hash' do |
35 | 35 | it 'should send the payload to the endpoint' do |
36 | 36 | expect(strategy).to receive(:call).with(:post, '/users', resource) |
37 | | - relation.create(payload) |
| 37 | + relation.push(payload) |
38 | 38 | end |
39 | 39 |
|
40 | | - it 'should set the context to :create' do |
41 | | - expect(strategy).to receive(:call).with(:post, '/users', satisfy { |r| r.context == :create }) |
42 | | - relation.create(payload) |
| 40 | + it 'should set the context to :push' do |
| 41 | + expect(strategy).to receive(:call).with(:post, '/users', satisfy { |r| r.context == :push }) |
| 42 | + relation.push(payload) |
43 | 43 | end |
44 | 44 | end |
45 | 45 |
|
|
48 | 48 |
|
49 | 49 | it 'should send the request to the endpoint' do |
50 | 50 | expect(strategy).to receive(:call).with(:post, '/users', resource) |
51 | | - relation.create(payload) |
| 51 | + relation.push(payload) |
52 | 52 | end |
53 | 53 |
|
54 | | - it 'should set the context to :create' do |
55 | | - expect(strategy).to receive(:call).with(:post, '/users', satisfy { |r| r.context == :create }) |
56 | | - relation.create(payload) |
| 54 | + it 'should set the context to :push' do |
| 55 | + expect(strategy).to receive(:call).with(:post, '/users', satisfy { |r| r.context == :push }) |
| 56 | + relation.push(payload) |
57 | 57 | end |
58 | 58 | end |
59 | 59 |
|
|
64 | 64 |
|
65 | 65 | it 'should send a simple payload to the endpoint' do |
66 | 66 | expect(strategy).to receive(:call).with(:post, '/users', resource) |
67 | | - relation.create(payload[:identifier]) |
| 67 | + relation.push(payload[:identifier]) |
68 | 68 | end |
69 | 69 | end |
70 | 70 |
|
|
73 | 73 |
|
74 | 74 | it 'should not send a payload to the endpoint' do |
75 | 75 | expect(strategy).to_not receive(:call) |
76 | | - relation.create(payload) |
| 76 | + relation.push(payload) |
77 | 77 | end |
78 | 78 | end |
79 | 79 |
|
80 | 80 | context 'when the operation is not permitted' do |
81 | 81 | before do |
82 | | - allow_any_instance_of(resource_type).to receive(:create?).and_return(false) |
| 82 | + allow_any_instance_of(resource_type).to receive(:push?).and_return(false) |
83 | 83 | end |
84 | 84 |
|
85 | 85 | it 'should not send a payload to the endpoint' do |
86 | 86 | expect(strategy).to_not receive(:call) |
87 | | - relation.create(payload) |
| 87 | + relation.push(payload) |
88 | 88 | end |
89 | 89 | end |
90 | 90 |
|
|
94 | 94 | end |
95 | 95 |
|
96 | 96 | it 'should not allow the operation' do |
97 | | - expect(resource.create?).to be(false) |
| 97 | + expect(resource.push?).to be(false) |
98 | 98 | end |
99 | 99 | end |
100 | 100 | end |
| 101 | + |
| 102 | + describe '.create' do |
| 103 | + it 'should be an alias for push' do |
| 104 | + expect(relation.method(:create)).to eq(relation.method(:push)) |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + describe '.update' do |
| 109 | + it 'should be an alias for push' do |
| 110 | + expect(relation.method(:update)).to eq(relation.method(:push)) |
| 111 | + end |
| 112 | + end |
101 | 113 | end |
0 commit comments