Skip to content

Commit 7e97fb0

Browse files
committed
Rename Operations::Create to Operations::Push
1 parent da21fac commit 7e97fb0

11 files changed

Lines changed: 72 additions & 63 deletions

File tree

lib/userlist/push.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'userlist/push/resource_collection'
66
require 'userlist/push/relation'
77

8-
require 'userlist/push/operations/create'
8+
require 'userlist/push/operations/push'
99
require 'userlist/push/operations/delete'
1010

1111
require 'userlist/push/user'
@@ -38,39 +38,39 @@ def initialize(configuration = {})
3838
attr_reader :config, :strategy
3939

4040
def events
41-
@events ||= Relation.new(self, Event, [Operations::Create])
41+
@events ||= Relation.new(self, Event, [Operations::Push])
4242
end
4343

4444
def users
45-
@users ||= Relation.new(self, User, [Operations::Create, Operations::Delete])
45+
@users ||= Relation.new(self, User, [Operations::Push, Operations::Delete])
4646
end
4747

4848
def companies
49-
@companies ||= Relation.new(self, Company, [Operations::Create, Operations::Delete])
49+
@companies ||= Relation.new(self, Company, [Operations::Push, Operations::Delete])
5050
end
5151

5252
def relationships
53-
@relationships ||= Relation.new(self, Relationship, [Operations::Create, Operations::Delete])
53+
@relationships ||= Relation.new(self, Relationship, [Operations::Push, Operations::Delete])
5454
end
5555

5656
def messages
57-
@messages ||= Relation.new(self, Message, [Operations::Create])
57+
@messages ||= Relation.new(self, Message, [Operations::Push])
5858
end
5959

6060
def event(payload = {})
61-
events.create(payload)
61+
events.push(payload)
6262
end
6363

6464
def user(payload = {})
65-
users.create(payload)
65+
users.push(payload)
6666
end
6767

6868
def company(payload = {})
69-
companies.create(payload)
69+
companies.push(payload)
7070
end
7171

7272
def message(payload = {})
73-
messages.create(payload)
73+
messages.push(payload)
7474
end
7575

7676
alias track event

lib/userlist/push/company.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Userlist
22
class Push
33
class Company < Resource
4-
include Operations::Create
4+
include Operations::Push
55
include Operations::Delete
66

77
def self.endpoint

lib/userlist/push/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Userlist
22
class Push
33
class Event < Resource
4-
include Operations::Create
4+
include Operations::Push
55

66
has_one :user, type: 'Userlist::Push::User'
77
has_one :company, type: 'Userlist::Push::Company'

lib/userlist/push/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Userlist
22
class Push
33
class Message < Resource
4-
include Operations::Create
4+
include Operations::Push
55

66
has_one :user, type: 'Userlist::Push::User'
77

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
module Userlist
22
class Push
33
module Operations
4-
module Create
4+
module Push
55
module ClassMethods
6-
def create(payload = {}, config = self.config)
6+
def push(payload = {}, config = self.config)
77
return false unless resource = from_payload(payload, config)
8-
return false unless resource.create?
8+
return false unless resource.push?
99

10-
strategy.call(:post, endpoint, resource.for_context(:create))
10+
strategy.call(:post, endpoint, resource.for_context(:push))
1111
end
1212

13-
alias push create
13+
alias create push
14+
alias update push
1415
end
1516

1617
def self.included(base)
1718
base.extend(ClassMethods)
1819
end
19-
20-
def create?
21-
push?
22-
end
2320
end
2421
end
2522
end

lib/userlist/push/relationship.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Userlist
22
class Push
33
class Relationship < Resource
4-
include Operations::Create
4+
include Operations::Push
55
include Operations::Delete
66

77
has_one :user, type: 'Userlist::Push::User'

lib/userlist/push/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Userlist
22
class Push
33
class User < Resource
4-
include Operations::Create
4+
include Operations::Push
55
include Operations::Delete
66

77
has_many :relationships, type: 'Userlist::Push::Relationship', inverse: :user

spec/userlist/push/operations/delete_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
relation.delete(payload)
1919
end
2020

21-
it 'should set the context to :create' do
21+
it 'should set the context to :delete' do
2222
expect(strategy).to receive(:call).with(:delete, '/users', satisfy { |r| r.context == :delete })
2323
relation.delete(payload)
2424
end
@@ -34,7 +34,7 @@
3434
relation.delete(payload)
3535
end
3636

37-
it 'should set the context to :create' do
37+
it 'should set the context to :delete' do
3838
expect(strategy).to receive(:call).with(:delete, '/users', satisfy { |r| r.context == :delete })
3939
relation.delete(payload)
4040
end
@@ -48,7 +48,7 @@
4848
relation.delete(payload)
4949
end
5050

51-
it 'should set the context to :create' do
51+
it 'should set the context to :delete' do
5252
expect(strategy).to receive(:call).with(:delete, '/users', satisfy { |r| r.context == :delete })
5353
relation.delete(payload)
5454
end
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
RSpec.describe Userlist::Push::Operations::Create do
3+
RSpec.describe Userlist::Push::Operations::Push do
44
let(:resource_type) { Userlist::Push::User }
55
let(:relation) { Userlist::Push::Relation.new(scope, resource_type, [described_class]) }
66
let(:scope) { Userlist::Push.new(push_strategy: strategy) }
@@ -17,29 +17,29 @@
1717
}
1818
end
1919

20-
describe '.create' do
20+
describe '.push' do
2121
before do
2222
allow(strategy).to receive(:call)
2323
end
2424

2525
it 'should create a new instance of the resource_type' do
2626
expect(resource_type).to receive(:new).with(payload, scope.config).and_return(resource)
27-
relation.create(payload)
27+
relation.push(payload)
2828
end
2929

3030
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))
3232
end
3333

3434
context 'when given a payload hash' do
3535
it 'should send the payload to the endpoint' do
3636
expect(strategy).to receive(:call).with(:post, '/users', resource)
37-
relation.create(payload)
37+
relation.push(payload)
3838
end
3939

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)
4343
end
4444
end
4545

@@ -48,12 +48,12 @@
4848

4949
it 'should send the request to the endpoint' do
5050
expect(strategy).to receive(:call).with(:post, '/users', resource)
51-
relation.create(payload)
51+
relation.push(payload)
5252
end
5353

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)
5757
end
5858
end
5959

@@ -64,7 +64,7 @@
6464

6565
it 'should send a simple payload to the endpoint' do
6666
expect(strategy).to receive(:call).with(:post, '/users', resource)
67-
relation.create(payload[:identifier])
67+
relation.push(payload[:identifier])
6868
end
6969
end
7070

@@ -73,18 +73,18 @@
7373

7474
it 'should not send a payload to the endpoint' do
7575
expect(strategy).to_not receive(:call)
76-
relation.create(payload)
76+
relation.push(payload)
7777
end
7878
end
7979

8080
context 'when the operation is not permitted' do
8181
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)
8383
end
8484

8585
it 'should not send a payload to the endpoint' do
8686
expect(strategy).to_not receive(:call)
87-
relation.create(payload)
87+
relation.push(payload)
8888
end
8989
end
9090

@@ -94,8 +94,20 @@
9494
end
9595

9696
it 'should not allow the operation' do
97-
expect(resource.create?).to be(false)
97+
expect(resource.push?).to be(false)
9898
end
9999
end
100100
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
101113
end

spec/userlist/push/relation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe Userlist::Push::Relation do
44
let(:scope) { double(:scope, config: config) }
55
let(:resource_type) { double(:resource_type, endpoint: '/messages') }
6-
let(:operations) { [Userlist::Push::Operations::Create, Userlist::Push::Operations::Delete] }
6+
let(:operations) { [Userlist::Push::Operations::Push, Userlist::Push::Operations::Delete] }
77
let(:config) { Userlist.config.merge(push_strategy: :null) }
88

99
subject { described_class.new(scope, resource_type, operations) }

0 commit comments

Comments
 (0)