straight 0.1.0

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.
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Straight::Order do
4
+
5
+ class Straight::Order
6
+
7
+ def status=(new_value)
8
+ # we later make sure this method also gets called
9
+ @original_status_setter_called = true
10
+ end
11
+
12
+ end
13
+
14
+ before(:each) do
15
+ @gateway = double("Straight Gateway mock")
16
+ @order = Straight::Order.new
17
+ @order.amount = 10
18
+ @order.gateway = @gateway
19
+ @order.address = 'address'
20
+ @order.keychain_id = 1
21
+ allow(@gateway).to receive(:order_status_changed).with(@order)
22
+ allow(@gateway).to receive(:fetch_transactions_for).with(@order.address).and_return([{ tid: 'xxx'}])
23
+ end
24
+
25
+ it "follows status check schedule" do
26
+ allow(@gateway).to receive(:fetch_transactions_for).with('address').and_return([])
27
+ allow(@gateway).to receive(:status_check_schedule).and_return(Straight::Gateway::DEFAULT_STATUS_CHECK_SCHEDULE)
28
+ [10, 20, 40, 80, 160, 320, 640].each do |i|
29
+ expect(@order).to receive(:sleep).with(i).exactly(6).times
30
+ end
31
+ @order.check_status_on_schedule
32
+ end
33
+
34
+ it "gets the last transaction for the current address, caches the request" do
35
+ expect(@gateway).to receive(:fetch_transactions_for).with(@order.address).once.and_return(true)
36
+ @order.transactions
37
+ @order.transactions
38
+ end
39
+
40
+ it "gets all transactions for the current address, caches the request" do
41
+ expect(@gateway).to receive(:fetch_transactions_for).with(@order.address).once.and_return(['t1', 't2'])
42
+ expect(@order.transaction).to eq('t1')
43
+ expect(@order.transaction).to eq('t1')
44
+ end
45
+
46
+ it "sets transaction id when the status is changed from 0" do
47
+ @order.status = 2
48
+ expect(@order.tid).to eq('xxx') # xxx because that's what we set in the allow() in before(:each) block
49
+ end
50
+
51
+ it "displays order attributes as json" do
52
+ allow(@order).to receive(:status).and_return(1)
53
+ expect(@order.to_json).to eq('{"status":1,"amount":10,"address":"address","tid":null}')
54
+ end
55
+
56
+ describe "assigning statuses" do
57
+
58
+ before(:each) do
59
+ allow(@gateway).to receive(:confirmations_required).and_return(1)
60
+ end
61
+
62
+ it "doesn't reload the transaction unless forced" do
63
+ @order.instance_variable_set(:@status, 2)
64
+ expect(@order).to_not receive(:transaction)
65
+ @order.status
66
+ end
67
+
68
+ it "sets status to :new if no transaction issued" do
69
+ expect(@order).to receive(:transaction).at_most(3).times.and_return(nil)
70
+ expect(@order.status(reload: true)).to eq(0)
71
+ end
72
+
73
+ it "sets status to :unconfirmed if transaction doesn't have enough confirmations" do
74
+ transaction = { confirmations: 0 }
75
+ expect(@order).to receive(:transaction).at_most(3).times.and_return(transaction)
76
+ expect(@order.status(reload: true)).to eq(1)
77
+ end
78
+
79
+ it "sets status to :paid if transaction has enough confirmations and the amount is correct" do
80
+ transaction = { confirmations: 1, total_amount: @order.amount }
81
+ expect(@order).to receive(:transaction).at_most(3).times.and_return(transaction)
82
+ expect(@order.status(reload: true)).to eq(2)
83
+ end
84
+
85
+ it "sets status to :underpaid if the total amount in a transaction is less than the amount of order" do
86
+ transaction = { confirmations: 1, total_amount: @order.amount-1 }
87
+ expect(@order).to receive(:transaction).at_most(3).times.and_return(transaction)
88
+ expect(@order.status(reload: true)).to eq(3)
89
+ end
90
+
91
+ it "sets status to :overderpaid if the total amount in a transaction is more than the amount of order" do
92
+ transaction = { confirmations: 1, total_amount: @order.amount+1 }
93
+ expect(@order).to receive(:transaction).at_most(3).times.and_return(transaction)
94
+ expect(@order.status(reload: true)).to eq(4)
95
+ end
96
+
97
+ it "invokes a callback on the gateway when status changes" do
98
+ transaction = { confirmations: 1, total_amount: @order.amount }
99
+ allow(@order).to receive(:transaction).and_return(transaction)
100
+ expect(@gateway).to receive(:order_status_changed).with(@order)
101
+ @order.status(reload: true)
102
+ end
103
+
104
+ it "calls the original status setter of the class that the module is included into" do
105
+ expect(@order.instance_variable_get(:@original_status_setter_called)).to be_falsy
106
+ @order.status = 1
107
+ expect(@order.instance_variable_get(:@original_status_setter_called)).to be_truthy
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1 @@
1
+ require_relative "../lib/straight"
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: straight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman Snitko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: money-tree
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: satoshi-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: github_api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.3
83
+ description: An engine for the Straight payment gateway software. Requires no state
84
+ to be saved (that is, no storage or DB). Its responsibilities only include processing
85
+ data coming from an actual gateway.
86
+ email: roman.snitko@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ files:
93
+ - ".document"
94
+ - ".rspec"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - VERSION
101
+ - lib/straight.rb
102
+ - lib/straight/blockchain_adapter.rb
103
+ - lib/straight/blockchain_adapters/blockchain_info_adapter.rb
104
+ - lib/straight/blockchain_adapters/helloblock_io_adapter.rb
105
+ - lib/straight/exchange_rate_adapter.rb
106
+ - lib/straight/exchange_rate_adapters/bitpay_adapter.rb
107
+ - lib/straight/exchange_rate_adapters/bitstamp_adapter.rb
108
+ - lib/straight/exchange_rate_adapters/coinbase_adapter.rb
109
+ - lib/straight/gateway.rb
110
+ - lib/straight/order.rb
111
+ - spec/lib/blockchain_adapters/blockchain_info_spec.rb
112
+ - spec/lib/blockchain_adapters/helloblock_io_spec.rb
113
+ - spec/lib/exchange_rate_adapter_spec.rb
114
+ - spec/lib/exchange_rate_adapters/bitpay_adapter_spec.rb
115
+ - spec/lib/exchange_rate_adapters/bitstamp_adapter_spec.rb
116
+ - spec/lib/exchange_rate_adapters/coinbase_adapter_spec.rb
117
+ - spec/lib/gateway_spec.rb
118
+ - spec/lib/order_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: http://github.com/snitko/straight
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.2.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: An engine for the Straight payment gateway software
144
+ test_files: []