coins_paid_rails 1.1.7 → 1.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
  SHA256:
3
- metadata.gz: 25025c942a4c630da89e160486f2c5d1f05ed9584ce7f2c4fa27d4bf54c738f3
4
- data.tar.gz: 5d8394faae19349b459dbd31e3277f047eda74eaaa67c9b632649100244170e7
3
+ metadata.gz: 2a245456681db498181920344cd14e9535d73f722674653a102d5edac3528a4e
4
+ data.tar.gz: 942f6799a1ae1784ea09810617c637bafd0745feba909a53779de1e4230ae33d
5
5
  SHA512:
6
- metadata.gz: f53a2431352a34504e6cca780e8a29b3492418ea7112ccfb647139f33e211cf98194e5964a37f837cc856a711db0f1f172bf878fbba7b5b6265ae3f4a610144a
7
- data.tar.gz: 49ef1f19b5924e1b2ffbc1c0ae485d3c185a8fa91796e676b7fdf07429e1d472a4770d253014e5c023ad3e12681d5969e10a8a6e0b8fb1abd24bc17e92a56b6d
6
+ metadata.gz: ebb41616c2ae9dfeee509b4c7cbcbd9589950ec0133974b118252081fa68662a2c9c10c8c5c2ea34b946a6b00f3d094e56a1a848dde062f09f07c681ed5aef79
7
+ data.tar.gz: c08a4d7d308e02fc81d547aa1361da7cbd48bd3cb1801af8890be00218eb3f01e415cfdd3b7ffe100620198c22485f3789c345ccb0a532827b4f3ad4d8bad67c
data/.circleci/config.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  version: 2.0
2
+
2
3
  defaults: &defaults
3
4
  docker:
4
- - image: circleci/ruby:2.5-stretch-node
5
- working_directory: ~/coins_paid
5
+ - image: cimg/ruby:2.7-node
6
+ working_directory: ~/project
6
7
 
7
8
  jobs:
8
9
  checkout_code:
@@ -10,10 +11,10 @@ jobs:
10
11
  steps:
11
12
  - checkout
12
13
  - run: mkdir log
13
- - save_cache:
14
- key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
14
+ - persist_to_workspace:
15
+ root: ~/project
15
16
  paths:
16
- - ~/coins_paid
17
+ - ./
17
18
 
18
19
  download_cc_reporter:
19
20
  <<: *defaults
@@ -25,45 +26,45 @@ jobs:
25
26
  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc/cc-test-reporter
26
27
  chmod +x ./cc/cc-test-reporter
27
28
  - persist_to_workspace:
28
- root: ~/coins_paid
29
+ root: ~/project
29
30
  paths:
30
31
  - cc/cc-test-reporter
31
32
 
32
33
  run_bundler:
33
34
  <<: *defaults
34
35
  steps:
36
+ - attach_workspace:
37
+ at: ~/project
35
38
  - restore_cache:
36
- key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
37
- - restore_cache:
38
- key: v4-bundle-{{ checksum "Gemfile.lock" }}
39
+ key: v1-bundle-{{ checksum "Gemfile.lock" }}
39
40
  - run: echo "export rvm_ignore_gemsets_flag=1" >> ~/.rvmrc
40
41
  - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
41
- - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
42
+ - run: bundle config set --local path 'vendor/bundle'
43
+ - run: bundle check || bundle install --path=vendor/bundle --jobs=4 --retry=3
42
44
  - save_cache:
43
- key: v4-bundle-{{ checksum "Gemfile.lock" }}
45
+ key: v1-bundle-{{ checksum "Gemfile.lock" }}
44
46
  paths:
45
- - ~/coins_paid/vendor/bundle
47
+ - ~/project/vendor/bundle
46
48
 
47
49
  run_rspec_tests:
48
50
  <<: *defaults
49
51
  docker:
50
- - image: circleci/ruby:2.5-stretch-node
52
+ - image: cimg/ruby:2.7-node
51
53
  environment:
52
54
  RACK_ENV: "test"
53
55
  CIRCLE_ARTIFACTS: "./tmp"
54
56
  steps:
55
- - restore_cache:
56
- key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
57
- - restore_cache:
58
- key: v4-bundle-{{ checksum "Gemfile.lock" }}
59
57
  - attach_workspace:
60
- at: ~/coins_paid
58
+ at: ~/project
59
+ - restore_cache:
60
+ key: v1-bundle-{{ checksum "Gemfile.lock" }}
61
61
  - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
62
- - run: bundle check --path vendor/bundle
62
+ - run: bundle config set --local path 'vendor/bundle'
63
+ - run: bundle check
63
64
  - run: bundle exec rspec spec
64
65
  - run: ./cc/cc-test-reporter format-coverage -t simplecov -o cc/codeclimate.rspec.json tmp/coverage/.resultset.json
65
66
  - persist_to_workspace:
66
- root: ~/coins_paid
67
+ root: ~/project
67
68
  paths:
68
69
  - cc/codeclimate.rspec.json
69
70
 
@@ -71,24 +72,12 @@ jobs:
71
72
  <<: *defaults
72
73
  steps:
73
74
  - attach_workspace:
74
- at: ~/coins_paid
75
+ at: ~/project
75
76
  - run:
76
77
  name: Upload coverage results to Code Climate
77
78
  command: |
78
79
  ./cc/cc-test-reporter upload-coverage -i cc/codeclimate.rspec.json
79
80
 
80
- deploy:
81
- <<: *defaults
82
- steps:
83
- - restore_cache:
84
- key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
85
- - restore_cache:
86
- key: v4-bundle-{{ checksum "Gemfile.lock" }}
87
- - run: mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts
88
- - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
89
- - run: bundle check --path vendor/bundle
90
- - run: bundle exec rake deploy:branch_or_label
91
-
92
81
  workflows:
93
82
  version: 2
94
83
  build_test_deploy:
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rails
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
6
+ NewCops: enable
7
+ SuggestExtensions: false
8
+
9
+ Naming/MethodParameterName:
10
+ MinNameLength: 1
11
+ Naming/VariableNumber:
12
+ Enabled: false
13
+
14
+ Lint/MissingCopEnableDirective:
15
+ Enabled: false
16
+
17
+ Layout/EmptyLineAfterMagicComment:
18
+ Enabled: false
19
+ Layout/LineLength:
20
+ Max: 120
21
+ Layout/MultilineOperationIndentation:
22
+ Enabled: false
23
+ Layout/MultilineMethodCallIndentation:
24
+ EnforcedStyle: indented_relative_to_receiver
25
+
26
+ Style/AsciiComments:
27
+ Enabled: false
28
+ Style/ClassAndModuleChildren:
29
+ Enabled: false
30
+ Style/Documentation:
31
+ Enabled: false
32
+ Style/FormatStringToken:
33
+ Enabled: false
34
+ Style/Lambda:
35
+ Enabled: false
36
+ Style/LambdaCall:
37
+ Enabled: false
38
+ Style/ModuleFunction:
39
+ Enabled: false
40
+ Style/PercentLiteralDelimiters:
41
+ PreferredDelimiters:
42
+ '%i': '()'
43
+ '%I': '()'
44
+ '%r': '{}'
45
+ '%w': '()'
46
+ '%W': '()'
47
+ Style/SignalException:
48
+ EnforcedStyle: 'only_raise'
49
+
50
+ Metrics/AbcSize:
51
+ Exclude:
52
+ - 'config/**/*'
53
+ - 'db/**/*'
54
+ - 'spec/**/*'
55
+ Metrics/BlockLength:
56
+ Exclude:
57
+ - 'config/**/*'
58
+ - 'db/**/*'
59
+ - 'spec/**/*'
60
+ Metrics/MethodLength:
61
+ Exclude:
62
+ - 'config/**/*'
63
+ - 'db/**/*'
64
+ - 'spec/**/*'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.7.5
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coins_paid_rails (1.1.7)
5
- activerecord (>= 4.2.0)
4
+ coins_paid_rails (1.3.0)
5
+ activerecord (~> 6.1.4)
6
6
  coins_paid_api (~> 1.0)
7
7
  dry-initializer (~> 3.0)
8
8
  dry-struct (~> 1.0)
@@ -10,51 +10,50 @@ PATH
10
10
  GEM
11
11
  remote: http://www.rubygems.org/
12
12
  specs:
13
- actionpack (5.2.4.4)
14
- actionview (= 5.2.4.4)
15
- activesupport (= 5.2.4.4)
16
- rack (~> 2.0, >= 2.0.8)
13
+ actionpack (6.1.5)
14
+ actionview (= 6.1.5)
15
+ activesupport (= 6.1.5)
16
+ rack (~> 2.0, >= 2.0.9)
17
17
  rack-test (>= 0.6.3)
18
18
  rails-dom-testing (~> 2.0)
19
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
- actionview (5.2.4.4)
21
- activesupport (= 5.2.4.4)
19
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
+ actionview (6.1.5)
21
+ activesupport (= 6.1.5)
22
22
  builder (~> 3.1)
23
23
  erubi (~> 1.4)
24
24
  rails-dom-testing (~> 2.0)
25
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
26
- activemodel (5.2.4.4)
27
- activesupport (= 5.2.4.4)
28
- activerecord (5.2.4.4)
29
- activemodel (= 5.2.4.4)
30
- activesupport (= 5.2.4.4)
31
- arel (>= 9.0)
32
- activesupport (5.2.4.4)
25
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
+ activemodel (6.1.5)
27
+ activesupport (= 6.1.5)
28
+ activerecord (6.1.5)
29
+ activemodel (= 6.1.5)
30
+ activesupport (= 6.1.5)
31
+ activesupport (6.1.5)
33
32
  concurrent-ruby (~> 1.0, >= 1.0.2)
34
- i18n (>= 0.7, < 2)
35
- minitest (~> 5.1)
36
- tzinfo (~> 1.1)
37
- arel (9.0.0)
33
+ i18n (>= 1.6, < 2)
34
+ minitest (>= 5.1)
35
+ tzinfo (~> 2.0)
36
+ zeitwerk (~> 2.3)
38
37
  builder (3.2.4)
39
38
  chunky_png (1.4.0)
40
- coins_paid_api (1.0.5)
39
+ coins_paid_api (1.1.0)
41
40
  dry-struct (~> 1.0)
42
41
  faraday (~> 0.12)
43
42
  faraday_middleware (~> 0.11)
44
- concurrent-ruby (1.1.7)
43
+ concurrent-ruby (1.1.10)
45
44
  crass (1.0.6)
46
- diff-lcs (1.4.4)
47
- docile (1.1.5)
48
- dry-configurable (0.12.1)
45
+ diff-lcs (1.5.0)
46
+ docile (1.4.0)
47
+ dry-configurable (0.14.0)
49
48
  concurrent-ruby (~> 1.0)
50
- dry-core (~> 0.5, >= 0.5.0)
51
- dry-container (0.7.2)
49
+ dry-core (~> 0.6)
50
+ dry-container (0.9.0)
52
51
  concurrent-ruby (~> 1.0)
53
- dry-configurable (~> 0.1, >= 0.1.3)
54
- dry-core (0.6.0)
52
+ dry-configurable (~> 0.13, >= 0.13.0)
53
+ dry-core (0.7.1)
55
54
  concurrent-ruby (~> 1.0)
56
- dry-inflector (0.2.0)
57
- dry-initializer (3.0.4)
55
+ dry-inflector (0.2.1)
56
+ dry-initializer (3.1.1)
58
57
  dry-logic (1.2.0)
59
58
  concurrent-ruby (~> 1.0)
60
59
  dry-core (~> 0.5, >= 0.5)
@@ -69,74 +68,74 @@ GEM
69
68
  dry-inflector (~> 0.1, >= 0.1.2)
70
69
  dry-logic (~> 1.0, >= 1.0.2)
71
70
  erubi (1.10.0)
72
- faraday (0.17.4)
71
+ faraday (0.17.5)
73
72
  multipart-post (>= 1.2, < 3)
74
73
  faraday_middleware (0.14.0)
75
74
  faraday (>= 0.7.4, < 1.0)
76
- i18n (1.8.5)
75
+ i18n (1.10.0)
77
76
  concurrent-ruby (~> 1.0)
78
77
  ice_nine (0.11.2)
79
- json (2.3.0)
80
- loofah (2.8.0)
78
+ loofah (2.15.0)
81
79
  crass (~> 1.0.2)
82
80
  nokogiri (>= 1.5.9)
83
81
  method_source (1.0.0)
84
- mini_portile2 (2.5.0)
85
- minitest (5.14.2)
82
+ mini_portile2 (2.8.0)
83
+ minitest (5.15.0)
86
84
  multipart-post (2.1.1)
87
- nokogiri (1.11.1)
88
- mini_portile2 (~> 2.5.0)
85
+ nokogiri (1.13.3)
86
+ mini_portile2 (~> 2.8.0)
89
87
  racc (~> 1.4)
90
- racc (1.5.2)
88
+ racc (1.6.0)
91
89
  rack (2.2.3)
92
90
  rack-test (1.1.0)
93
91
  rack (>= 1.0, < 3)
94
92
  rails-dom-testing (2.0.3)
95
93
  activesupport (>= 4.2.0)
96
94
  nokogiri (>= 1.6)
97
- rails-html-sanitizer (1.3.0)
95
+ rails-html-sanitizer (1.4.2)
98
96
  loofah (~> 2.3)
99
- railties (5.2.4.4)
100
- actionpack (= 5.2.4.4)
101
- activesupport (= 5.2.4.4)
97
+ railties (6.1.5)
98
+ actionpack (= 6.1.5)
99
+ activesupport (= 6.1.5)
102
100
  method_source
103
- rake (>= 0.8.7)
104
- thor (>= 0.19.0, < 2.0)
105
- rake (13.0.1)
106
- rqrcode (2.1.0)
101
+ rake (>= 12.2)
102
+ thor (~> 1.0)
103
+ rake (13.0.6)
104
+ rqrcode (2.1.1)
107
105
  chunky_png (~> 1.0)
108
106
  rqrcode_core (~> 1.0)
109
107
  rqrcode_core (1.2.0)
110
- rspec-core (3.10.0)
111
- rspec-support (~> 3.10.0)
112
- rspec-expectations (3.10.0)
108
+ rspec-core (3.11.0)
109
+ rspec-support (~> 3.11.0)
110
+ rspec-expectations (3.11.0)
113
111
  diff-lcs (>= 1.2.0, < 2.0)
114
- rspec-support (~> 3.10.0)
112
+ rspec-support (~> 3.11.0)
115
113
  rspec-its (1.3.0)
116
114
  rspec-core (>= 3.0.0)
117
115
  rspec-expectations (>= 3.0.0)
118
- rspec-mocks (3.10.0)
116
+ rspec-mocks (3.11.0)
119
117
  diff-lcs (>= 1.2.0, < 2.0)
120
- rspec-support (~> 3.10.0)
121
- rspec-rails (4.0.1)
122
- actionpack (>= 4.2)
123
- activesupport (>= 4.2)
124
- railties (>= 4.2)
125
- rspec-core (~> 3.9)
126
- rspec-expectations (~> 3.9)
127
- rspec-mocks (~> 3.9)
128
- rspec-support (~> 3.9)
129
- rspec-support (3.10.0)
130
- simplecov (0.13.0)
131
- docile (~> 1.1.0)
132
- json (>= 1.8, < 3)
133
- simplecov-html (~> 0.10.0)
134
- simplecov-html (0.10.2)
118
+ rspec-support (~> 3.11.0)
119
+ rspec-rails (5.1.1)
120
+ actionpack (>= 5.2)
121
+ activesupport (>= 5.2)
122
+ railties (>= 5.2)
123
+ rspec-core (~> 3.10)
124
+ rspec-expectations (~> 3.10)
125
+ rspec-mocks (~> 3.10)
126
+ rspec-support (~> 3.10)
127
+ rspec-support (3.11.0)
128
+ simplecov (0.21.2)
129
+ docile (~> 1.1)
130
+ simplecov-html (~> 0.11)
131
+ simplecov_json_formatter (~> 0.1)
132
+ simplecov-html (0.12.3)
133
+ simplecov_json_formatter (0.1.4)
135
134
  sqlite3 (1.4.2)
136
- thor (1.0.1)
137
- thread_safe (0.3.6)
138
- tzinfo (1.2.8)
139
- thread_safe (~> 0.1)
135
+ thor (1.2.1)
136
+ tzinfo (2.0.4)
137
+ concurrent-ruby (~> 1.0)
138
+ zeitwerk (2.5.4)
140
139
 
141
140
  PLATFORMS
142
141
  ruby
@@ -150,4 +149,4 @@ DEPENDENCIES
150
149
  sqlite3
151
150
 
152
151
  BUNDLED WITH
153
- 1.17.1
152
+ 2.2.32
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coins_paid_rails'
3
3
  s.authors = ['Artem Biserov(artembiserov)', 'Oleg Ivanov(morhekil)']
4
- s.version = '1.1.7'
4
+ s.version = '1.3.0'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'CoinsPaid Rails Integration'
7
7
  s.license = 'MIT'
8
8
 
9
9
  s.add_runtime_dependency 'coins_paid_api', '~> 1.0'
10
- s.add_runtime_dependency 'activerecord', '>= 4.2.0'
10
+ s.add_runtime_dependency 'activerecord', '~> 6.1.4'
11
11
  s.add_runtime_dependency 'dry-initializer', '~> 3.0'
12
12
  s.add_runtime_dependency 'dry-struct', '~> 1.0'
13
13
  s.add_development_dependency 'rspec-rails'
@@ -18,7 +18,8 @@ module CoinsPaid
18
18
 
19
19
  def call
20
20
  ActiveRecord::Base.transaction do
21
- CoinsPaidAddress.lock.find_or_create_by!(request_data.attributes.slice(:foreign_id, :currency)) do |address|
21
+ lookup_attrs = request_data.attributes.slice(:foreign_id, :convert_to, :currency)
22
+ CoinsPaidAddress.lock.find_or_create_by!(lookup_attrs) do |address|
22
23
  response = CoinsPaid::API.take_address(request_data.attributes)
23
24
  address.assign_attributes(response.attributes)
24
25
  end
data/lib/coins_paid.rb CHANGED
@@ -3,34 +3,14 @@ require 'dry-struct'
3
3
  require 'dry-initializer'
4
4
  require_relative 'coins_paid/address'
5
5
  require_relative 'coins_paid/coins_paid_address'
6
- require_relative 'coins_paid/qr_code'
7
6
 
8
7
  module CoinsPaid
9
8
  module_function
10
9
 
11
10
  UnknownCurrency = Class.new RuntimeError
12
11
 
13
- DEFAULT_CONVERT_TO = ENV['COINS_PAID_CURRENCY']
14
-
15
- ADDRESS_PREFIXES = {
16
- 'BTC' => 'bitcoin',
17
- 'BCH' => 'bitcoincash',
18
- 'DOGE' => 'doge',
19
- 'ETH' => 'ethereum',
20
- 'EURTE' => 'ethereum',
21
- 'LTC' => 'litecoin',
22
- 'USDT' => 'bitcoin',
23
- 'USDTE' => 'ethereum',
24
- 'TRX' => 'tron',
25
- 'USDTT' => 'tron'
26
- }.freeze
27
-
28
- def address(foreign_id, currency:)
29
- Address.new(foreign_id: foreign_id, currency: currency, convert_to: DEFAULT_CONVERT_TO).call
30
- end
31
-
32
- def qr_code(player_id, currency:, label:, message:)
33
- QrCode.new(player_id, currency: currency, label: label, message: message)
12
+ def address(foreign_id, currency:, convert_to: currency)
13
+ Address.new(foreign_id: foreign_id, currency: currency, convert_to: convert_to).call
34
14
  end
35
15
 
36
16
  def currency(name)
@@ -38,6 +18,6 @@ module CoinsPaid
38
18
  end
39
19
 
40
20
  def issued_addresses(foreign_id)
41
- CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency)
21
+ CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency, :convert_to)
42
22
  end
43
23
  end
@@ -5,18 +5,19 @@ module CoinsPaid
5
5
  module_function
6
6
 
7
7
  def get
8
- <<RUBY
9
- create_table :coins_paid_addresses do |t|
10
- t.string :foreign_id, null: false
11
- t.string :currency, null: false
12
- t.string :address, null: false
13
- t.string :tag
14
- t.integer :external_id, null: false
15
-
16
- t.timestamps
17
- t.index [:foreign_id, :currency], unique: true
18
- end
19
- RUBY
8
+ <<~RUBY
9
+ create_table :coins_paid_addresses do |t|
10
+ t.string :foreign_id, null: false
11
+ t.string :currency, null: false
12
+ t.string :convert_to, null: false
13
+ t.string :address, null: false
14
+ t.string :tag
15
+ t.integer :external_id, null: false
16
+
17
+ t.timestamps
18
+ t.index [:foreign_id, :currency, :convert_to], name: :address_currencies, unique: true
19
+ end
20
+ RUBY
20
21
  end
21
22
  end
22
23
  end
@@ -6,7 +6,7 @@ module CoinsPaid
6
6
  module Generators
7
7
  class MigrationGenerator < ActiveRecord::Generators::Base
8
8
  argument :name, default: 'create_coins_paid_addresses'
9
- source_root File.expand_path("templates", __dir__)
9
+ source_root File.expand_path('templates', __dir__)
10
10
 
11
11
  def copy_coins_paid_migration
12
12
  migration_template 'migration.rb', "#{db_migrate_path}/#{file_name}.rb"
data/spec/address_spec.rb CHANGED
@@ -1,56 +1,95 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe CoinsPaid, '.address' do
4
- let(:foreign_key) { 'user-id:2048' }
4
+ let(:foreign_id) { 'user-id:2048' }
5
5
  let(:currency) { 'BTC' }
6
- let(:full_address_attributes) do
7
- {
8
- foreign_id: foreign_key,
9
- currency: currency
10
- }.merge(address_attributes)
11
- end
6
+ let(:convert_to) { 'EUR' }
12
7
  let(:address_attributes) do
13
8
  {
14
9
  external_id: 1,
15
10
  address: '12983h13ro1hrt24it432t',
16
- tag: 'tag-123',
11
+ tag: 'tag-123'
17
12
  }
18
13
  end
19
- subject(:take_address) { described_class.address(foreign_key, currency: currency) }
14
+ let(:api_request_args) { { foreign_id: foreign_id, currency: currency, convert_to: convert_to } }
15
+
16
+ subject(:take_address) { described_class.address(foreign_id, currency: currency, convert_to: convert_to) }
20
17
 
21
- context 'when there is existing record' do
22
- let!(:address) do
23
- CoinsPaid::CoinsPaidAddress.create!(full_address_attributes)
18
+ context 'when there is a previously stored address record' do
19
+ let(:stored_address_attributes) do
20
+ address_attributes.merge(
21
+ foreign_id: foreign_id,
22
+ currency: currency,
23
+ convert_to: recorded_convert_to
24
+ )
25
+ end
26
+
27
+ let!(:stored_address) do
28
+ CoinsPaid::CoinsPaidAddress.create!(stored_address_attributes)
24
29
  end
25
30
 
26
31
  before do
27
- allow(CoinsPaid::API).to receive(:take_address)
32
+ allow(CoinsPaid::API).to receive(:take_address).and_return(
33
+ CoinsPaid::API::TakeAddress::Response.new(address_attributes)
34
+ )
28
35
  end
29
36
 
30
- it 'returns existing record' do
31
- expect(take_address).to eq address
37
+ context 'with the same convert_to value' do
38
+ let(:recorded_convert_to) { convert_to }
32
39
 
33
- expect(CoinsPaid::API).not_to have_received(:take_address)
40
+ it 'returns existing record' do
41
+ expect do
42
+ expect(take_address).to eq stored_address
43
+ end.to_not change(CoinsPaid::CoinsPaidAddress, :count)
44
+ expect(CoinsPaid::API).not_to have_received(:take_address)
45
+ end
34
46
  end
35
- end
36
47
 
37
- context 'when coins paid api responds with error' do
38
- before do
39
- allow(CoinsPaid::API).to receive(:take_address).and_raise(CoinsPaid::API::Error)
40
- end
48
+ context 'with a different convert_to value' do
49
+ let(:recorded_convert_to) { 'DOGE' }
41
50
 
42
- it 'raises error' do
43
- expect { take_address }.to raise_error(CoinsPaid::API::Error)
51
+ it 'requests and records new address' do
52
+ expect do
53
+ new_address_attrs = stored_address_attributes.merge(convert_to: convert_to)
54
+ expect(take_address).to have_attributes(new_address_attrs)
55
+ end.to change(CoinsPaid::CoinsPaidAddress, :count).by(1)
56
+ expect(CoinsPaid::API).to have_received(:take_address).with(api_request_args)
57
+ end
44
58
  end
45
59
  end
46
60
 
47
- context 'when coins paid return valid response' do
48
- before do
49
- allow(CoinsPaid::API).to receive(:take_address).and_return(CoinsPaid::API::TakeAddress::Response.new(address_attributes))
61
+ context 'when there is no recorded address' do
62
+ context 'and coins paid api responds with error' do
63
+ before do
64
+ allow(CoinsPaid::API).to receive(:take_address).and_raise(CoinsPaid::API::Error)
65
+ end
66
+
67
+ it 'raises error' do
68
+ expect { take_address }.to raise_error(CoinsPaid::API::Error)
69
+ end
50
70
  end
51
71
 
52
- it 'creates new address' do
53
- expect(take_address).to have_attributes(full_address_attributes)
72
+ context 'and coins paid returns valid response' do
73
+ before do
74
+ allow(CoinsPaid::API).to receive(:take_address).and_return(
75
+ CoinsPaid::API::TakeAddress::Response.new(address_attributes)
76
+ )
77
+ end
78
+
79
+ let(:new_address_attrs) do
80
+ address_attributes.merge(
81
+ foreign_id: foreign_id,
82
+ currency: currency,
83
+ convert_to: convert_to
84
+ )
85
+ end
86
+
87
+ it 'creates new address' do
88
+ expect do
89
+ expect(take_address).to have_attributes(new_address_attrs)
90
+ end.to change(CoinsPaid::CoinsPaidAddress, :count).by(1)
91
+ expect(CoinsPaid::API).to have_received(:take_address).with(api_request_args)
92
+ end
54
93
  end
55
94
  end
56
95
  end
@@ -6,15 +6,15 @@ describe CoinsPaid, '.issued_addresses' do
6
6
  it 'returns addresses with requested foreign_id ordered by currency' do
7
7
  attrs = {
8
8
  foreign_id: foreign_id,
9
- currency: 'BTC',
10
9
  address: 'addr',
11
10
  external_id: 1
12
11
  }
13
12
 
14
- addr1 = CoinsPaid::CoinsPaidAddress.create!(attrs)
15
- addr2 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH'))
16
- CoinsPaid::CoinsPaidAddress.create!(attrs.merge(foreign_id: 555))
13
+ addr1 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'BTC', convert_to: 'EUR'))
14
+ addr2 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH', convert_to: 'EUR'))
15
+ addr3 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH', convert_to: 'ETH'))
16
+ CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'BTC', convert_to: 'EUR', foreign_id: 555))
17
17
 
18
- expect(CoinsPaid.issued_addresses(foreign_id)).to eq [addr1, addr2]
18
+ expect(CoinsPaid.issued_addresses(foreign_id)).to eq [addr1, addr3, addr2]
19
19
  end
20
20
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ if ENV['CIRCLE_ARTIFACTS']
6
6
  end
7
7
 
8
8
  require 'active_record'
9
- require "active_record/railtie"
9
+ require 'active_record/railtie'
10
10
  require 'rspec/rails'
11
11
  require 'rspec/its'
12
12
  require 'rqrcode'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coins_paid_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Biserov(artembiserov)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-28 00:00:00.000000000 Z
12
+ date: 2022-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coins_paid_api
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: activerecord
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 4.2.0
34
+ version: 6.1.4
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 4.2.0
41
+ version: 6.1.4
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: dry-initializer
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +90,7 @@ files:
90
90
  - ".circleci/config.yml"
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
+ - ".rubocop.yml"
93
94
  - ".ruby-version"
94
95
  - Gemfile
95
96
  - Gemfile.lock
@@ -97,7 +98,6 @@ files:
97
98
  - lib/coins_paid.rb
98
99
  - lib/coins_paid/address.rb
99
100
  - lib/coins_paid/coins_paid_address.rb
100
- - lib/coins_paid/qr_code.rb
101
101
  - lib/coins_paid_rails.rb
102
102
  - lib/generators/coins_paid/migration_data.rb
103
103
  - lib/generators/coins_paid/migration_generator.rb
@@ -105,7 +105,6 @@ files:
105
105
  - spec/address_spec.rb
106
106
  - spec/currency_spec.rb
107
107
  - spec/issued_addresses_spec.rb
108
- - spec/qr_code_spec.rb
109
108
  - spec/spec_helper.rb
110
109
  - spec/support/database/create_table.rb
111
110
  homepage:
@@ -127,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
126
  - !ruby/object:Gem::Version
128
127
  version: '0'
129
128
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.6
129
+ rubygems_version: 3.1.6
132
130
  signing_key:
133
131
  specification_version: 4
134
132
  summary: CoinsPaid Rails Integration
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CoinsPaid
4
- class QrCode
5
- include Dry::Initializer.define -> do
6
- param :player_id
7
- option :currency
8
- option :label
9
- option :message
10
- end
11
-
12
- def url
13
- known_url? ? "#{token_type}:#{address.address}?label=#{encode(label)}&message=#{encode(message)}" : nil
14
- end
15
-
16
- def address
17
- @address ||= CoinsPaid.address(player_id, currency: currency)
18
- end
19
-
20
- def svg
21
- RQRCode::QRCode.new(url || address.address).as_svg(
22
- offset: 0,
23
- color: '000',
24
- shape_rendering: 'crispEdges',
25
- module_size: 3,
26
- standalone: true
27
- )
28
- end
29
-
30
- private
31
-
32
- def token_type
33
- ADDRESS_PREFIXES[currency]
34
- end
35
-
36
- def encode(string)
37
- URI.encode_www_form_component(string)
38
- end
39
-
40
- def known_url?
41
- token_type.present?
42
- end
43
- end
44
- end
data/spec/qr_code_spec.rb DELETED
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe CoinsPaid, '.qr_code' do
4
- let(:foreign_id) { 123 }
5
- let(:currency) { 'BTC' }
6
- let(:address) { 'abc123' }
7
- let(:coins_paid_address) do
8
- instance_double CoinsPaid::CoinsPaidAddress,
9
- currency: currency,
10
- address: address
11
- end
12
- subject(:qr_code) do
13
- described_class.qr_code(
14
- foreign_id,
15
- currency: currency,
16
- label: 'RedStar deposit',
17
- message: 'Make a deposit to RedStar'
18
- )
19
- end
20
-
21
- before do
22
- allow(CoinsPaid).to receive(:address).with(foreign_id, currency: currency).and_return(coins_paid_address)
23
- end
24
-
25
- context 'it is known how to build payment url for the currency' do
26
- let(:currency) { 'BTC' }
27
- let(:url) { "bitcoin:#{address}?label=RedStar+deposit&message=Make+a+deposit+to+RedStar" }
28
-
29
- describe '#url' do
30
- its(:url) { is_expected.to eq url }
31
- end
32
-
33
- describe '#svg' do
34
- it 'encodes payment url' do
35
- expect(RQRCode::QRCode).to receive(:new).with(url).and_call_original
36
- qr_code.svg
37
- end
38
- end
39
- end
40
-
41
- context 'it is not known how to build payment url for the currency' do
42
- let(:currency) { 'BNB' }
43
-
44
- describe '#url' do
45
- its(:url) { is_expected.to be_nil }
46
- end
47
-
48
- describe '#svg' do
49
- it 'encodes payment address' do
50
- expect(RQRCode::QRCode).to receive(:new).with(address).and_call_original
51
- qr_code.svg
52
- end
53
- end
54
- end
55
-
56
- context '#address' do
57
- its(:address) { is_expected.to eq coins_paid_address }
58
- end
59
- end