proclaimer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f828bb32881de602413bf79b13d3d7cfe93e75e1
4
- data.tar.gz: 22716b13b309b4fe2d049eefb1f8d28bf93e699d
3
+ metadata.gz: 52c69df73835fe00be8d56f7f7deeee774ad6a5e
4
+ data.tar.gz: 0c6b1b232a4c32c4886576acde714c3bc29e917d
5
5
  SHA512:
6
- metadata.gz: 8721b30d047b3f7ff45becdee6933ad63b083cbbcb010e3dba79b3cbee9b1374842355a104b3aacfcceb7ddea9e71ecd1c71e38532de26f8138a1ecf338c1e57
7
- data.tar.gz: 47e10b63f25a17f165dd0a54050824c5f5d5c43254ae4342ee0db493be48fd01d3912c1b0e70bfc6a7a2badfc7500721bd990d281231a112febc80184b511637
6
+ metadata.gz: dce7f586aabe933a013d6c905588839a739886a6181c0e6c61db22e8fc7d6c8835de4d3a97e3589c8693690aa98865cbfa7626f374d0c4d77a1e5c411da71308
7
+ data.tar.gz: fcfde9c493ee65e6b3dd47864b6a667539cbf8eb7d14fd8594050ff4c181a67b81951f4d87ea814888f830652ed0ac081bddf1eaafd3a4dd1c09235d50c32969
data/Gemfile.lock CHANGED
@@ -74,7 +74,7 @@ GIT
74
74
  PATH
75
75
  remote: .
76
76
  specs:
77
- proclaimer (0.2.0)
77
+ proclaimer (0.3.0)
78
78
  spree_backend (~> 3.0.0)
79
79
 
80
80
  GEM
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ Product.class_eval do
3
+ after_save :broadcast_changes, if: :anything_changed?
4
+
5
+ private
6
+
7
+ def broadcast_changes
8
+ ActiveSupport::Notifications.instrument(
9
+ "spree.product.updated",
10
+ product: self
11
+ )
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Proclaimer
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -1,36 +1,38 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe Spree::Order do
4
- before { stub_const("EMPTY_PAYLOAD", Object.new) }
3
+ module Spree
4
+ RSpec.describe Order, type: :model do
5
+ before { stub_const("EMPTY_PAYLOAD", Object.new) }
5
6
 
6
- context "when order is first created" do
7
- it "does not instrument any order event" do
8
- payload = EMPTY_PAYLOAD
7
+ context "when order is first created" do
8
+ it "does not instrument any order event" do
9
+ payload = EMPTY_PAYLOAD
9
10
 
10
- ActiveSupport::Notifications.subscribed(
11
- -> (*args) { payload = args.last },
12
- /^spree\.order/
13
- ) do
14
- create(:order)
11
+ ActiveSupport::Notifications.subscribed(
12
+ -> (*args) { payload = args.last },
13
+ /^spree\.order/
14
+ ) do
15
+ create(:order)
15
16
 
16
- expect(payload).to eq EMPTY_PAYLOAD
17
+ expect(payload).to eq EMPTY_PAYLOAD
18
+ end
17
19
  end
18
20
  end
19
- end
20
21
 
21
- context "when order is complete" do
22
- it "instruments order.complete event" do
23
- payload = EMPTY_PAYLOAD
22
+ context "when order is complete" do
23
+ it "instruments order.complete event" do
24
+ payload = EMPTY_PAYLOAD
24
25
 
25
- ActiveSupport::Notifications.subscribed(
26
- -> (*args) { payload = args.last },
27
- "spree.order.complete"
28
- ) do
29
- order = create(:order_with_line_items, state: "confirm")
30
- create(:payment, amount: order.total, order: order)
31
- order.next!
26
+ ActiveSupport::Notifications.subscribed(
27
+ -> (*args) { payload = args.last },
28
+ "spree.order.complete"
29
+ ) do
30
+ order = create(:order_with_line_items, state: "confirm")
31
+ create(:payment, amount: order.total, order: order)
32
+ order.next!
32
33
 
33
- expect(payload[:order]).to eq order
34
+ expect(payload[:order]).to eq order
35
+ end
34
36
  end
35
37
  end
36
38
  end
@@ -6,8 +6,8 @@ module Spree
6
6
  describe "#update_shipments_with_status_tracking" do
7
7
  it "calls shipment#broadcast on shipments that have changed state" do
8
8
  fake_shipments = [
9
- fake_shipment_with_state('pending', 'ready'),
10
- fake_shipment_with_state('pending')
9
+ fake_shipment_with_state("pending", "ready"),
10
+ fake_shipment_with_state("pending")
11
11
  ]
12
12
  fake_order = double(Order, shipments: fake_shipments)
13
13
  updater = described_class.new(fake_order)
@@ -1,18 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe Spree::Payment do
4
- context "when payment is complete" do
5
- it "instruments payment.complete event" do
6
- payload = nil
3
+ module Spree
4
+ RSpec.describe Payment, type: :model do
5
+ context "when payment is complete" do
6
+ it "instruments payment.complete event" do
7
+ payload = nil
7
8
 
8
- ActiveSupport::Notifications.subscribed(
9
- -> (*args) { payload = args.last },
10
- "spree.payment.complete"
11
- ) do
12
- payment = create(:payment)
13
- payment.complete
9
+ ActiveSupport::Notifications.subscribed(
10
+ -> (*args) { payload = args.last },
11
+ "spree.payment.complete"
12
+ ) do
13
+ payment = create(:payment)
14
+ payment.complete
14
15
 
15
- expect(payload[:payment]).to eq payment
16
+ expect(payload[:payment]).to eq payment
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ module Spree
4
+ RSpec.describe Product, type: :model do
5
+ context "when changes are present" do
6
+ it "instruments spree.product.updated event" do
7
+ product = build_product
8
+
9
+ product.run_callbacks(:save)
10
+
11
+ expect(ActiveSupport::Notifications).
12
+ to have_received(:instrument).
13
+ with("spree.product.updated", product: product)
14
+ end
15
+ end
16
+
17
+ context "when no changes are present" do
18
+ it "instruments spree.product.updated event" do
19
+ product = build_product
20
+ allow(product).to receive(:anything_changed?) { false }
21
+
22
+ product.run_callbacks(:save)
23
+
24
+ expect(ActiveSupport::Notifications).
25
+ not_to have_received(:instrument).
26
+ with("spree.product.updated", product: product)
27
+ end
28
+ end
29
+
30
+ def build_product
31
+ build(:product).tap do
32
+ allow(ActiveSupport::Notifications).to receive(:instrument)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,34 +1,36 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Spree::Refund do
4
- before { stub_const("EMPTY_PAYLOAD", Object.new) }
3
+ module Spree
4
+ RSpec.describe Refund, type: :model do
5
+ before { stub_const("EMPTY_PAYLOAD", Object.new) }
5
6
 
6
- context "when refund have not been processed" do
7
- it "does not instrument any refund event" do
8
- payload = EMPTY_PAYLOAD
7
+ context "when refund have not been processed" do
8
+ it "does not instrument any refund event" do
9
+ payload = EMPTY_PAYLOAD
9
10
 
10
- ActiveSupport::Notifications.subscribed(
11
- -> (*args) { payload = args.last },
12
- /^spree\.refund/
13
- ) do
14
- build(:refund)
11
+ ActiveSupport::Notifications.subscribed(
12
+ -> (*args) { payload = args.last },
13
+ /^spree\.refund/
14
+ ) do
15
+ build(:refund)
15
16
 
16
- expect(payload).to eq EMPTY_PAYLOAD
17
+ expect(payload).to eq EMPTY_PAYLOAD
18
+ end
17
19
  end
18
20
  end
19
- end
20
21
 
21
- context "when the refund has been processed" do
22
- it "instruments refund.complete event" do
23
- payload = EMPTY_PAYLOAD
22
+ context "when the refund has been processed" do
23
+ it "instruments refund.complete event" do
24
+ payload = EMPTY_PAYLOAD
24
25
 
25
- ActiveSupport::Notifications.subscribed(
26
- -> (*args) { payload = args.last },
27
- "spree.refund.complete"
28
- ) do
29
- refund = create(:refund, payment: create(:payment, amount: 100))
26
+ ActiveSupport::Notifications.subscribed(
27
+ -> (*args) { payload = args.last },
28
+ "spree.refund.complete"
29
+ ) do
30
+ refund = create(:refund, payment: create(:payment, amount: 100))
30
31
 
31
- expect(payload[:refund]).to eq refund
32
+ expect(payload[:refund]).to eq refund
33
+ end
32
34
  end
33
35
  end
34
36
  end
@@ -1,58 +1,61 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe Spree::Shipment do
4
- context "when shipment is pending" do
5
- it "instruments shipment.pending event" do
6
- payload = nil
7
-
8
- ActiveSupport::Notifications.subscribed(
9
- -> (*args) { payload = args.last },
10
- "spree.shipment.pending"
11
- ) do
12
- shipment = create(:shipment)
13
-
14
- expect(payload[:shipment]).to eq shipment
3
+ module Spree
4
+ RSpec.describe Shipment, type: :model do
5
+ context "when shipment is pending" do
6
+ it "instruments shipment.pending event" do
7
+ payload = nil
8
+
9
+ ActiveSupport::Notifications.subscribed(
10
+ -> (*args) { payload = args.last },
11
+ "spree.shipment.pending"
12
+ ) do
13
+ shipment = create(:shipment)
14
+
15
+ expect(payload[:shipment]).to eq shipment
16
+ end
15
17
  end
16
18
  end
17
- end
18
19
 
19
- context "when shipment is ready" do
20
- it "instruments shipment.ready event" do
21
- shipment = create(:shipment)
22
- allow(shipment).to receive(:determine_state) { 'ready' }
23
- allow(ActiveSupport::Notifications).to receive(:instrument)
20
+ context "when shipment is ready" do
21
+ it "instruments shipment.ready event" do
22
+ shipment = create(:shipment)
23
+ allow(shipment).to receive(:determine_state) { 'ready' }
24
+ allow(ActiveSupport::Notifications).to receive(:instrument)
24
25
 
25
- shipment.ready
26
+ shipment.ready
26
27
 
27
- expect(ActiveSupport::Notifications).
28
- to have_received(:instrument).
29
- with("spree.shipment.ready", shipment: shipment)
28
+ expect(ActiveSupport::Notifications).
29
+ to have_received(:instrument).
30
+ with("spree.shipment.ready", shipment: shipment)
31
+ end
30
32
  end
31
- end
32
33
 
33
- context "when shipment is canceled" do
34
- it "instruments shipment.canceled event" do
35
- shipment = create(:shipment)
36
- allow(ActiveSupport::Notifications).to receive(:instrument)
34
+ context "when shipment is canceled" do
35
+ it "instruments shipment.canceled event" do
36
+ shipment = create(:shipment)
37
+ allow(ActiveSupport::Notifications).to receive(:instrument)
37
38
 
38
- shipment.cancel
39
+ shipment.cancel
39
40
 
40
- expect(ActiveSupport::Notifications).
41
- to have_received(:instrument).
42
- with("spree.shipment.canceled", shipment: shipment)
41
+ expect(ActiveSupport::Notifications).
42
+ to have_received(:instrument).
43
+ with("spree.shipment.canceled", shipment: shipment)
44
+ end
43
45
  end
44
- end
45
46
 
46
- describe "#broadcast_state" do
47
- it "instruments shipment.STATE event" do
48
- shipment = build(:shipment, state: 'pending')
49
- allow(ActiveSupport::Notifications).to receive(:instrument)
47
+ describe "#broadcast_state" do
48
+ it "instruments shipment.STATE event" do
49
+ shipment = build(:shipment, state: 'pending')
50
+ allow(ActiveSupport::Notifications).to receive(:instrument)
50
51
 
51
- shipment.broadcast_state
52
+ shipment.broadcast_state
52
53
 
53
- expect(ActiveSupport::Notifications).
54
- to have_received(:instrument).
55
- with("spree.shipment.pending", shipment: shipment)
54
+ expect(ActiveSupport::Notifications).
55
+ to have_received(:instrument).
56
+ with("spree.shipment.pending", shipment: shipment)
57
+ end
56
58
  end
57
59
  end
58
60
  end
61
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclaimer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prem Sichanugrist
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-06 00:00:00.000000000 Z
13
+ date: 2015-10-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: spree_backend
@@ -168,6 +168,7 @@ files:
168
168
  - app/models/spree/order_decorator.rb
169
169
  - app/models/spree/order_updater_decorator.rb
170
170
  - app/models/spree/payment_decorator.rb
171
+ - app/models/spree/product_decorator.rb
171
172
  - app/models/spree/refund_decorator.rb
172
173
  - app/models/spree/shipment_decorator.rb
173
174
  - bin/rails
@@ -181,6 +182,7 @@ files:
181
182
  - spec/models/spree/order_spec.rb
182
183
  - spec/models/spree/order_updater_spec.rb
183
184
  - spec/models/spree/payment_spec.rb
185
+ - spec/models/spree/product_spec.rb
184
186
  - spec/models/spree/refund_spec.rb
185
187
  - spec/models/spree/shipment_spec.rb
186
188
  - spec/proclaimer_spec.rb
@@ -214,6 +216,7 @@ test_files:
214
216
  - spec/models/spree/order_spec.rb
215
217
  - spec/models/spree/order_updater_spec.rb
216
218
  - spec/models/spree/payment_spec.rb
219
+ - spec/models/spree/product_spec.rb
217
220
  - spec/models/spree/refund_spec.rb
218
221
  - spec/models/spree/shipment_spec.rb
219
222
  - spec/proclaimer_spec.rb