coins_paid_rails 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5f4f94846ba1e3ffa0c4e6d019833198eb380884a25cd83a328cf783c9556ef
4
- data.tar.gz: 49529291f106e21617c3bff7f9f41c50571fc2d48647c8a876053fd9f16fc2ce
3
+ metadata.gz: 2a245456681db498181920344cd14e9535d73f722674653a102d5edac3528a4e
4
+ data.tar.gz: 942f6799a1ae1784ea09810617c637bafd0745feba909a53779de1e4230ae33d
5
5
  SHA512:
6
- metadata.gz: 2e88d8f07132fedf82433dc08bafcc3849252b746d4269b9e5b01f6f3d54c20ecaac2c10f4f1a6fe4c5efdfa43ab47ed9202775ba83842d7620d1c6d49a9b1a9
7
- data.tar.gz: ef914fe2d13cda6e5b6775f5364dcc99c4ec88c09d07ed766554fdc263050a163db7278939a661be797cf5f223d66d86e7f0679ab7e2e5a5eb855995c090ab88
6
+ metadata.gz: ebb41616c2ae9dfeee509b4c7cbcbd9589950ec0133974b118252081fa68662a2c9c10c8c5c2ea34b946a6b00f3d094e56a1a848dde062f09f07c681ed5aef79
7
+ data.tar.gz: c08a4d7d308e02fc81d547aa1361da7cbd48bd3cb1801af8890be00218eb3f01e415cfdd3b7ffe100620198c22485f3789c345ccb0a532827b4f3ad4d8bad67c
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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coins_paid_rails (1.1.8)
4
+ coins_paid_rails (1.3.0)
5
5
  activerecord (~> 6.1.4)
6
6
  coins_paid_api (~> 1.0)
7
7
  dry-initializer (~> 3.0)
@@ -36,14 +36,14 @@ GEM
36
36
  zeitwerk (~> 2.3)
37
37
  builder (3.2.4)
38
38
  chunky_png (1.4.0)
39
- coins_paid_api (1.0.7)
39
+ coins_paid_api (1.1.0)
40
40
  dry-struct (~> 1.0)
41
41
  faraday (~> 0.12)
42
42
  faraday_middleware (~> 0.11)
43
43
  concurrent-ruby (1.1.10)
44
44
  crass (1.0.6)
45
- diff-lcs (1.4.4)
46
- docile (1.1.5)
45
+ diff-lcs (1.5.0)
46
+ docile (1.4.0)
47
47
  dry-configurable (0.14.0)
48
48
  concurrent-ruby (~> 1.0)
49
49
  dry-core (~> 0.6)
@@ -75,7 +75,6 @@ GEM
75
75
  i18n (1.10.0)
76
76
  concurrent-ruby (~> 1.0)
77
77
  ice_nine (0.11.2)
78
- json (2.3.0)
79
78
  loofah (2.15.0)
80
79
  crass (~> 1.0.2)
81
80
  nokogiri (>= 1.5.9)
@@ -102,22 +101,22 @@ GEM
102
101
  rake (>= 12.2)
103
102
  thor (~> 1.0)
104
103
  rake (13.0.6)
105
- rqrcode (2.1.0)
104
+ rqrcode (2.1.1)
106
105
  chunky_png (~> 1.0)
107
106
  rqrcode_core (~> 1.0)
108
107
  rqrcode_core (1.2.0)
109
- rspec-core (3.10.1)
110
- rspec-support (~> 3.10.0)
111
- rspec-expectations (3.10.1)
108
+ rspec-core (3.11.0)
109
+ rspec-support (~> 3.11.0)
110
+ rspec-expectations (3.11.0)
112
111
  diff-lcs (>= 1.2.0, < 2.0)
113
- rspec-support (~> 3.10.0)
112
+ rspec-support (~> 3.11.0)
114
113
  rspec-its (1.3.0)
115
114
  rspec-core (>= 3.0.0)
116
115
  rspec-expectations (>= 3.0.0)
117
- rspec-mocks (3.10.2)
116
+ rspec-mocks (3.11.0)
118
117
  diff-lcs (>= 1.2.0, < 2.0)
119
- rspec-support (~> 3.10.0)
120
- rspec-rails (5.0.2)
118
+ rspec-support (~> 3.11.0)
119
+ rspec-rails (5.1.1)
121
120
  actionpack (>= 5.2)
122
121
  activesupport (>= 5.2)
123
122
  railties (>= 5.2)
@@ -125,12 +124,13 @@ GEM
125
124
  rspec-expectations (~> 3.10)
126
125
  rspec-mocks (~> 3.10)
127
126
  rspec-support (~> 3.10)
128
- rspec-support (3.10.2)
129
- simplecov (0.13.0)
130
- docile (~> 1.1.0)
131
- json (>= 1.8, < 3)
132
- simplecov-html (~> 0.10.0)
133
- simplecov-html (0.10.2)
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)
134
134
  sqlite3 (1.4.2)
135
135
  thor (1.2.1)
136
136
  tzinfo (2.0.4)
@@ -1,7 +1,7 @@
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.2.0'
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'
@@ -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
@@ -9,7 +9,7 @@ module CoinsPaid
9
9
 
10
10
  UnknownCurrency = Class.new RuntimeError
11
11
 
12
- def address(foreign_id, currency:, convert_to:)
12
+ def address(foreign_id, currency:, convert_to: currency)
13
13
  Address.new(foreign_id: foreign_id, currency: currency, convert_to: convert_to).call
14
14
  end
15
15
 
@@ -18,6 +18,6 @@ module CoinsPaid
18
18
  end
19
19
 
20
20
  def issued_addresses(foreign_id)
21
- CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency)
21
+ CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency, :convert_to)
22
22
  end
23
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,57 +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
6
  let(:convert_to) { 'EUR' }
7
- let(:full_address_attributes) do
8
- {
9
- foreign_id: foreign_key,
10
- currency: currency
11
- }.merge(address_attributes)
12
- end
13
7
  let(:address_attributes) do
14
8
  {
15
9
  external_id: 1,
16
10
  address: '12983h13ro1hrt24it432t',
17
- tag: 'tag-123',
11
+ tag: 'tag-123'
18
12
  }
19
13
  end
20
- subject(:take_address) { described_class.address(foreign_key, currency: currency, convert_to: convert_to) }
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) }
21
17
 
22
- context 'when there is existing record' do
23
- let!(:address) do
24
- 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)
25
29
  end
26
30
 
27
31
  before do
28
- 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
+ )
29
35
  end
30
36
 
31
- it 'returns existing record' do
32
- expect(take_address).to eq address
37
+ context 'with the same convert_to value' do
38
+ let(:recorded_convert_to) { convert_to }
33
39
 
34
- 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
35
46
  end
36
- end
37
47
 
38
- context 'when coins paid api responds with error' do
39
- before do
40
- allow(CoinsPaid::API).to receive(:take_address).and_raise(CoinsPaid::API::Error)
41
- end
48
+ context 'with a different convert_to value' do
49
+ let(:recorded_convert_to) { 'DOGE' }
42
50
 
43
- it 'raises error' do
44
- 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
45
58
  end
46
59
  end
47
60
 
48
- context 'when coins paid return valid response' do
49
- before do
50
- 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
51
70
  end
52
71
 
53
- it 'creates new address' do
54
- 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
55
93
  end
56
94
  end
57
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.2.0
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: 2022-03-25 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
@@ -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