amountable 0.3.1 → 0.5.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: ddad2c59d957b1f0b01390e301141baa98422f644ccc965f66946670f1d42112
4
- data.tar.gz: 834d8c9530e849eb6d65e461251a59faa4495e2b787e71733b83f6cb9333c257
3
+ metadata.gz: 65db41fdb8408b564c411d3ccd1af1e472283c5c3d3f315eafc32b5a9f027315
4
+ data.tar.gz: 5741d0ea7a24844389f7f522fca71f180b4271d0572647d0ccbb110ad1506d03
5
5
  SHA512:
6
- metadata.gz: cc16662084b3068fbc45586360e37b33edd0b6c4fd7fd531bea0ab0f0cbe0eb6b64751f8dbed95f5325e4c210978c0b4cbb2183853b27898234ccf3a397b0502
7
- data.tar.gz: 6bb3891dbefa950390c037d066d5d16990475fdbd373b8d10500ec79355cdc03fb104aa2089b15247a0a4fe8a2f8ad3372f1d2cb32e2f5906d733ee2149b98e0
6
+ metadata.gz: ee011dcc7d65f146f331243798ce8c2198994215f9b6a565b1e859270eb38a852bd137bcb45dcdb0cd60eae7b43ba90d57d70dffc2669213b42e21123f954d65
7
+ data.tar.gz: 0a509e297d204a95326072236cc036b493b95e90204bc5170410b07163b9760135797e3928fedd97668c242565addd26eb76845523cacd2a72b9e3089a0cdfcf
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -0,0 +1,58 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby:
15
+ - '3.1'
16
+ - '3.0'
17
+ - '2.7'
18
+ activerecord:
19
+ - '7.0'
20
+ - '6.1'
21
+ - '6.0'
22
+ - '5.2'
23
+ exclude:
24
+ - activerecord: '5.2'
25
+ ruby: '3.0'
26
+ - activerecord: '5.2'
27
+ ruby: '3.1'
28
+ services:
29
+ postgres:
30
+ image: postgres:12
31
+ ports:
32
+ - 5432:5432
33
+ env:
34
+ POSTGRES_HOST_AUTH_METHOD: trust
35
+ POSTGRES_DB: amountable_test
36
+ options: >-
37
+ --health-cmd pg_isready
38
+ --health-interval 10s
39
+ --health-timeout 5s
40
+ --health-retries 5
41
+
42
+ name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.activerecord }}
43
+ env:
44
+ BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.activerecord }}.gemfile
45
+ steps:
46
+ - uses: actions/checkout@v2
47
+ - run: |
48
+ sudo apt-get -yqq install libpq-dev
49
+ - uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: ${{ matrix.ruby }}
52
+ bundler-cache: true
53
+ - run: |
54
+ bundle exec rake
55
+ env:
56
+ PGHOST: 127.0.0.1
57
+ PGUSER: postgres
58
+ RAILS_ENV: test
@@ -0,0 +1,34 @@
1
+ name: Publish Public Gem
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-ruby@v1
16
+ - name: Build
17
+ run: |
18
+ gem build *.gemspec
19
+ - name: Publish to Github
20
+ run: |
21
+ mkdir -p $HOME/.gem
22
+ touch $HOME/.gem/credentials
23
+ chmod 0600 $HOME/.gem/credentials
24
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
+ gem push --verbose --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
26
+ env:
27
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
28
+ OWNER: ${{ github.repository_owner }}
29
+ continue-on-error: true
30
+ - name: Publish to RubyGems
31
+ run: |
32
+ gem push --verbose *.gem
33
+ env:
34
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_TOKEN}}
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ gemfiles/*.lock
11
+ *.log
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour
1
+ --force-color
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright © 2015-2016, Instacart
1
+ Copyright © 2015-2021, Instacart
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted, provided that the above
data/amountable.gemspec CHANGED
@@ -15,11 +15,10 @@ Gem::Specification.new do |gem|
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.test_files = gem.files.grep(%r{^spec/})
17
17
  gem.require_paths = ['lib']
18
- gem.required_ruby_version = '>= 2.1.1'
18
+ gem.required_ruby_version = '>= 2.7'
19
19
 
20
- gem.add_dependency 'activerecord', '>= 4.1', '< 5.3'
21
- gem.add_dependency 'activesupport', '>= 4.1', '< 5.3'
22
- gem.add_dependency 'activerecord-import', '~> 0.19.1'
20
+ gem.add_dependency 'activerecord', '>= 5.2', '< 8'
21
+ gem.add_dependency 'activerecord-import', '>= 0.19.1'
23
22
  gem.add_dependency 'money-rails', '>=1.7.0'
24
23
  gem.add_dependency 'monetize'
25
24
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  class CreateAmounts < ActiveRecord::Migration
4
4
  def change
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 5.2.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 6.0.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 6.1.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 7.0.0"
@@ -1,21 +1,7 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  class Amount < ActiveRecord::Base
5
- class_attribute :columns
6
- self.columns = []
7
-
8
- def self.column(name, sql_type = nil, default = nil, null = true)
9
- type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.new
10
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, type, null)
11
- end
12
-
13
- column :amountable_type, :string, nil, false
14
- column :amountable_id, :integer, nil, false
15
- column :value_currency, :string, nil, true
16
- column :value_cents, :integer, 0, false
17
- column :name, :string, nil, false
18
-
19
5
  include Amountable::Operations
20
6
 
21
7
  belongs_to :amountable, polymorphic: true
@@ -31,6 +17,5 @@ module Amountable
31
17
  raise StandardError.new("Can't persist amount to database") if persistable == false
32
18
  super
33
19
  end
34
-
35
20
  end
36
- end
21
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module JsonbMethods
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  class NilAmount
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module Operations
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module TableMethods
@@ -19,15 +19,15 @@ module Amountable
19
19
  amount.value
20
20
  end
21
21
 
22
- def save(args = {})
22
+ def save(**args)
23
23
  ActiveRecord::Base.transaction do
24
- save_amounts if super(args)
24
+ save_amounts if super
25
25
  end
26
26
  end
27
27
 
28
- def save!(args = {})
28
+ def save!(**args)
29
29
  ActiveRecord::Base.transaction do
30
- save_amounts! if super(args)
30
+ save_amounts! if super
31
31
  end
32
32
  end
33
33
 
@@ -1,5 +1,5 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  class VirtualAmount
data/lib/amountable.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  extend ActiveSupport::Autoload
@@ -119,6 +119,7 @@ module Amountable
119
119
  super
120
120
  end
121
121
  end
122
+ ruby2_keywords :where if Module.private_method_defined?(:ruby2_keywords)
122
123
 
123
124
  def where_json(opts, *rest)
124
125
  values = []
@@ -136,6 +137,7 @@ module Amountable
136
137
  query = [query.join(' AND ')] + values
137
138
  where(query, *rest).where(opts, *rest)
138
139
  end
140
+ ruby2_keywords :where_json if Module.private_method_defined?(:ruby2_keywords)
139
141
 
140
142
  def pg_json_field_access(name, field = :cents)
141
143
  name = name.to_sym
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -23,7 +23,7 @@ describe Amountable do
23
23
  expect(amount.persisted?).to be true
24
24
  end
25
25
  expect do
26
- expect(order.update_attributes(sub_total: Money.new(200)))
26
+ expect(order.update(sub_total: Money.new(200)))
27
27
  end.not_to change { Amountable::Amount.count }
28
28
  end
29
29
 
@@ -80,7 +80,7 @@ describe Amountable do
80
80
  expect { subscription.save }.not_to change { Amountable::Amount.count }
81
81
  expect(amount.persisted?).to be false
82
82
  end
83
- subscription.update_attributes(sub_total: Money.new(200))
83
+ subscription.update(sub_total: Money.new(200))
84
84
  expect(subscription.sub_total).to eq(Money.new(200))
85
85
  expect(subscription.total).to eq(Money.new(200))
86
86
  subscription.sub_total = Money.zero
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  class Order < ActiveRecord::Base
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  if jsonb_available?
4
4
  class Subscription < ActiveRecord::Base
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  ActiveRecord::Schema.define do
4
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  ENV['RAILS_ENV'] = 'test'
4
4
  require 'rails'
@@ -1,4 +1,6 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
+
3
+ require "activerecord-import/base"
2
4
 
3
5
  db_name = ENV['DB'] || 'postgresql'
4
6
  spec_dir = Pathname.new(File.dirname(__FILE__)) / '..'
@@ -6,12 +8,17 @@ database_yml = spec_dir.join('internal/config/database.yml')
6
8
 
7
9
  fail "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample" unless File.exist?(database_yml)
8
10
 
11
+ module ActiveRecord::Import::Connection
12
+ ruby2_keywords :establish_connection if Module.private_method_defined?(:ruby2_keywords)
13
+ end
14
+
9
15
  ActiveRecord::Migration.verbose = false
10
16
  ActiveRecord::Base.default_timezone = :utc
11
17
  ActiveRecord::Base.configurations = YAML.load_file(database_yml)
12
18
  ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
13
- ActiveRecord::Base.logger.level = ENV['TRAVIS'] ? ::Logger::ERROR : ::Logger::DEBUG
14
- config = ActiveRecord::Base.configurations[db_name]
19
+ ActiveRecord::Base.logger.level = ENV['CI'] ? ::Logger::ERROR : ::Logger::DEBUG
20
+ configs = ActiveRecord::Base.configurations
21
+ config = configs.try(:find_db_config, db_name) || configs[db_name]
15
22
 
16
23
  begin
17
24
  ActiveRecord::Base.establish_connection(db_name.to_sym)
@@ -30,13 +37,7 @@ rescue
30
37
  end
31
38
 
32
39
  def jsonb_available?
33
- return @@jsonb_available if defined?(@@jsonb_available)
34
- @@jsonb_available = if ActiveRecord::Base.connection.class.ancestors.include?(ActiveRecord::Import::PostgreSQLAdapter)
35
- version = /PostgreSQL\s(\d+.\d+.\d+)\s/.match(ActiveRecord::Base.connection.execute("select version();")[0]['version'])[1].split('.').map(&:to_i)
36
- version[0] >= 9 && version[1] >= 3
37
- else
38
- false
39
- end
40
+ true
40
41
  end
41
42
 
42
43
  require_relative '../internal/db/schema'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amountable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Turlay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,52 +16,32 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.3'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.1'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.3'
33
- - !ruby/object:Gem::Dependency
34
- name: activesupport
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '4.1'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '5.3'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '4.1'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '5.3'
32
+ version: '8'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: activerecord-import
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
- - - "~>"
37
+ - - ">="
58
38
  - !ruby/object:Gem::Version
59
39
  version: 0.19.1
60
40
  type: :runtime
61
41
  prerelease: false
62
42
  version_requirements: !ruby/object:Gem::Requirement
63
43
  requirements:
64
- - - "~>"
44
+ - - ">="
65
45
  - !ruby/object:Gem::Version
66
46
  version: 0.19.1
67
47
  - !ruby/object:Gem::Dependency
@@ -198,15 +178,21 @@ executables: []
198
178
  extensions: []
199
179
  extra_rdoc_files: []
200
180
  files:
181
+ - ".github/dependabot.yml"
182
+ - ".github/workflows/CI.yml"
183
+ - ".github/workflows/gem-publish-public.yml"
201
184
  - ".gitignore"
202
185
  - ".rspec"
203
- - ".travis.yml"
204
186
  - Gemfile
205
187
  - LICENSE
206
188
  - README.md
207
189
  - Rakefile
208
190
  - amountable.gemspec
209
191
  - db/migrate/0_create_amounts.rb
192
+ - gemfiles/activerecord_5.2.gemfile
193
+ - gemfiles/activerecord_6.0.gemfile
194
+ - gemfiles/activerecord_6.1.gemfile
195
+ - gemfiles/activerecord_7.0.gemfile
210
196
  - lib/amountable.rb
211
197
  - lib/amountable/amount.rb
212
198
  - lib/amountable/jsonb_methods.rb
@@ -237,15 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
223
  requirements:
238
224
  - - ">="
239
225
  - !ruby/object:Gem::Version
240
- version: 2.1.1
226
+ version: '2.7'
241
227
  required_rubygems_version: !ruby/object:Gem::Requirement
242
228
  requirements:
243
229
  - - ">="
244
230
  - !ruby/object:Gem::Version
245
231
  version: '0'
246
232
  requirements: []
247
- rubyforge_project:
248
- rubygems_version: 2.7.6
233
+ rubygems_version: 3.2.32
249
234
  signing_key:
250
235
  specification_version: 4
251
236
  summary: Easy Money fields for your Rails models.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2
4
- addons:
5
- postgresql: "9.4"