retentiongrid 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c46c8b19021285df0a40f8227bacc72f2e351244
4
- data.tar.gz: 81150b36efc5b8429a71cae3e80a0c03308f5e17
3
+ metadata.gz: 296a60c0128c31e8dcac9d228abbfa45368304af
4
+ data.tar.gz: f7f6913b175940dd7201754c834f50172d4d5fe7
5
5
  SHA512:
6
- metadata.gz: 214c590b5de8447506031dd303fd811480e71068b79c609a7379e8d9d2b568eb0663a74abad8f9565801cf3278fac65a7c9e50528fced47ad0b3f1be4e9378df
7
- data.tar.gz: 001b8861a1af6f4b796f86b0077cda67cc3117415061dc8992ba75fe86e12ad8c41b3d05a5b319c084442113b619c8986743e9730f80940f4648f543bf276cf5
6
+ metadata.gz: b9a8e54ef544bc1fd23dcee0666b23acb156dae2bc6b5cd05d553d34811a633156f1170ab1a62310e06c70f09d71e9713fee18471a1712a38287363baef472b6
7
+ data.tar.gz: 2e63450795275aa8377f4f7c0841fc78f4e2fd957a16f852ab0b21d79a71f0caa0105da8f52179ab3e13e7b54bacc94352cb892775dd65e92238e78b69afd9f1
@@ -31,7 +31,7 @@ module Retentiongrid
31
31
  def self.find(line_item_id)
32
32
  begin
33
33
  result = Api.get("#{BASE_PATH}/#{line_item_id}")
34
- new(result.parsed_response["rg_line_item"])
34
+ new(result.parsed_response["rg_item"])
35
35
  rescue NotFound
36
36
  nil
37
37
  end
@@ -42,7 +42,7 @@ module Retentiongrid
42
42
  # @raise [Httparty::Error] for all sorts of HTTP statuses.
43
43
  def save!
44
44
  result = Api.post("#{BASE_PATH}/#{line_item_id}", body: attributes.to_json)
45
- new(result.parsed_response["rg_line_item"])
45
+ new(result.parsed_response["rg_item"])
46
46
  end
47
47
 
48
48
  # Delete this line item at retention grid
@@ -24,7 +24,9 @@ module Retentiongrid
24
24
 
25
25
  def initialize(attribs={})
26
26
  super
27
- @order_created_at = Time.parse(order_created_at) unless order_created_at.nil?
27
+ if order_created_at.class == String && !order_created_at.nil?
28
+ @order_created_at = Time.parse(order_created_at)
29
+ end
28
30
  end
29
31
 
30
32
  # relations
@@ -16,10 +16,10 @@ module Retentiongrid
16
16
 
17
17
  def initialize(attribs={})
18
18
  super
19
- if product_created_at.class == "String" && !product_created_at.nil?
19
+ if product_created_at.class == String && !product_created_at.nil?
20
20
  @product_created_at = Time.parse(product_created_at)
21
21
  end
22
- if @product_updated_at.class == "String" && !product_updated_at.nil?
22
+ if @product_updated_at.class == String && !product_updated_at.nil?
23
23
  @product_updated_at = Time.parse(product_updated_at)
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Retentiongrid
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ include Retentiongrid
3
+ RSpec.describe LineItem do
4
+
5
+ before do
6
+ WebMock.disable_net_connect!
7
+ end
8
+
9
+ def valid_line_items
10
+ <<-EOF
11
+ {
12
+ "rg_item": {
13
+ "line_item_id": "20377",
14
+ "order_id": 12977635,
15
+ "price": "4.5",
16
+ "quantity": 1,
17
+ "product_id": 25,
18
+ "variant_id": null,
19
+ "sku": "",
20
+ "name": "Protestsülze"
21
+ }
22
+ }
23
+ EOF
24
+ end
25
+
26
+ let(:api) { Api.new }
27
+
28
+ context '#find' do
29
+
30
+ subject do
31
+ stub_request(:get, "http://retentiongrid.apiary-mock.com/line_items/20377").
32
+ to_return(:status => 200, :body => valid_line_items, :headers => {'Content-Type' => 'application/json'})
33
+ LineItem.find(20377)
34
+ end
35
+
36
+ it "should build a LineItem from API response" do
37
+ expect(subject.class).to eql Retentiongrid::LineItem
38
+ end
39
+
40
+ it "should parse line_item_id correctly" do
41
+ expect(subject.line_item_id).to eql '20377'
42
+ end
43
+
44
+ end
45
+
46
+ context '#create' do
47
+ end
48
+
49
+ context '#delete' do
50
+
51
+ before :each do
52
+ stub_request(:delete, "http://retentiongrid.apiary-mock.com/line_items/#{subject.line_item_id}").to_return(:status => 204, :body => '')
53
+ end
54
+
55
+ it "should send delete to API" do
56
+ expect(subject.destroy).to eql true
57
+ end
58
+ end
59
+
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retentiongrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Bünte
@@ -153,6 +153,7 @@ files:
153
153
  - spec/factories/orders.rb
154
154
  - spec/factories/products.rb
155
155
  - spec/integration/customer_spec.rb
156
+ - spec/integration/line_item_spec.rb
156
157
  - spec/integration/order_spec.rb
157
158
  - spec/integration/product_spec.rb
158
159
  - spec/models/customer_spec.rb
@@ -190,6 +191,7 @@ test_files:
190
191
  - spec/factories/orders.rb
191
192
  - spec/factories/products.rb
192
193
  - spec/integration/customer_spec.rb
194
+ - spec/integration/line_item_spec.rb
193
195
  - spec/integration/order_spec.rb
194
196
  - spec/integration/product_spec.rb
195
197
  - spec/models/customer_spec.rb