Skip to content

Commit

Permalink
Merge pull request #8 from dribbble/patrick/newer-rails
Browse files Browse the repository at this point in the history
Update to modern versions of libraries
  • Loading branch information
pbyrne committed Aug 24, 2021
2 parents ec055cc + 050fc93 commit 18c0d22
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 54 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on: push

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- gemfile: rails_5_1
ruby: 2.7

- gemfile: rails_5_2
ruby: 2.7

- gemfile: rails_6_0
ruby: 2.7

- gemfile: rails_6_1
ruby: 2.7

- gemfile: rails_6_1
ruby: 3.0

name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: false

- name: Bundle install
run: |
bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/${{ matrix.gemfile }}.gemfile"
bundle install --jobs 4 --retry 3
- name: Run tests
run: |
bundle exec rspec
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: ruby
rvm:
- 2.0.0
- 2.1.1
- 2.6
- 2.7
- 3.0
gemfile:
- gemfiles/rails_3.gemfile
- gemfiles/rails_4.gemfile
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_6_1.gemfile
22 changes: 16 additions & 6 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
appraise "rails-3" do
gem "activerecord", "~> 3"
gem "activesupport", "~> 3"
appraise "rails-5-1" do
gem "activerecord", "~> 5.1.7"
gem "activerecord", "~> 5.1.7"
end

appraise "rails-4" do
gem "activerecord", "~> 4"
gem "activesupport", "~> 4"
appraise "rails-5-2" do
gem "activerecord", "~> 5.2.6"
gem "activerecord", "~> 5.2.6"
end

appraise "rails-6-0" do
gem "activerecord", "~> 6.0.4"
gem "activerecord", "~> 6.0.4"
end

appraise "rails-6-1" do
gem "activerecord", "~> 6.1.4"
gem "activerecord", "~> 6.1.4"
end
15 changes: 8 additions & 7 deletions allowed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Gem::Specification.new do |s|
s.name = "allowed"
s.version = "0.2.1"
s.platform = Gem::Platform::RUBY
s.authors = ["Tristan Dunn"]
s.authors = ["Tristan Dunn", "Patrick Byrne"]
s.email = "support@dribbble.com"
s.homepage = "https://github.com/dribbble/allowed"
s.summary = "Throttling of ActiveRecord model creations."
Expand All @@ -13,11 +13,12 @@ Gem::Specification.new do |s|
s.test_files = Dir["spec/**/*"].to_a
s.require_path = "lib"

s.add_dependency "activerecord", ">= 3"
s.add_dependency "activesupport", ">= 3"
s.add_dependency "activerecord", ">= 5.1"
s.add_dependency "activesupport", ">= 5.1"

s.add_development_dependency "appraisal", "1.0.2"
s.add_development_dependency "rake", "10.4.2"
s.add_development_dependency "rspec", "3.1.0"
s.add_development_dependency "sqlite3", "1.3.10"
s.add_development_dependency "appraisal", "~> 2.4.1"
s.add_development_dependency "pry"
s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 3.10"
s.add_development_dependency "sqlite3", "~> 1.4"
end
8 changes: 0 additions & 8 deletions gemfiles/rails_3.gemfile

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/rails_4.gemfile

This file was deleted.

7 changes: 7 additions & 0 deletions gemfiles/rails_5_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 5.1.7"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_5_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 5.2.6"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 6.0.4"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 6.1.4"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/allowed/limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def allow(limit, options = {}, &block)
end

def handle_throttles
@_throttle_failures.each do |throttle|
@_throttle_failures&.each do |throttle|
throttle.callback.call(self)
end
@_throttle_failures = []
Expand Down
11 changes: 5 additions & 6 deletions spec/lib/allowed/limit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,24 @@
it "adds validation callback" do
subject.allow(limit, options)

expect(subject).to have_callback(:validate, :validate_throttles)
expect(subject).to have_callback(:before, :validate, :validate_throttles)
end

it "only calls validation callback on create" do
subject.allow(limit, options)

instance = subject.new

allow(instance).to receive(:validate_throttles)
allow(instance).to receive(:handle_throttles)
expect(instance).to receive(:validate_throttles).once

instance.save
instance.save

expect(instance).to have_received(:validate_throttles).once
end

it "adds after rollback callback" do
subject.allow(limit, options)

expect(subject).to have_callback(:rollback, :handle_throttles, kind: :after, on: :create)
expect(subject).to have_callback(:after, :rollback, :handle_throttles)
end
end

Expand Down
16 changes: 2 additions & 14 deletions spec/support/have_callback.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
RSpec::Matchers.define :have_callback do |type, name, options|
RSpec::Matchers.define :have_callback do |kind, type, name|
match do |record|
options ||= {}
callbacks = record.__send__(:"_#{type}_callbacks")
callbacks.any? do |callback|
return false unless callback.raw_filter == name
return false unless options[:kind].nil? || callback.kind == options[:kind]
return true if options[:on].nil?

if callback.respond_to?(:options)
options[:on] == callback.options[:on]
else
if_options = callback.instance_variable_get("@if")
if_options.any? do |if_option|
if_option =~ /#{options[:on]}/
end
end
callback.matches?(kind, name)
end
end
end

0 comments on commit 18c0d22

Please sign in to comment.