Skip to content

Commit

Permalink
Add appraisal for testing multiple versions of Rails.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Jun 27, 2014
1 parent 3e1a0e4 commit a5fcd74
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
Gemfile.lock
gemfiles/*.gemfile.lock
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -2,3 +2,6 @@ language: ruby
rvm:
- 2.0.0
- 2.1.1
gemfile:
- gemfiles/rails_3.gemfile
- gemfiles/rails_4.gemfile
9 changes: 9 additions & 0 deletions Appraisals
@@ -0,0 +1,9 @@
appraise "rails-3" do
gem "activerecord", "~> 3"
gem "activesupport", "~> 3"
end

appraise "rails-4" do
gem "activerecord", "~> 4"
gem "activesupport", "~> 4"
end
8 changes: 7 additions & 1 deletion Rakefile
Expand Up @@ -7,4 +7,10 @@ RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end

task default: :spec
if ENV["APPRAISAL_INITIALIZED"] || ENV["CI"]
task default: :spec
else
task :default do
exec "bundle exec appraisal rake spec"
end
end
13 changes: 7 additions & 6 deletions allowed.gemspec
Expand Up @@ -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", ">= 3"
s.add_dependency "activesupport", ">= 3"

s.add_development_dependency "sqlite3", "1.3.9"
s.add_development_dependency "bourne", "1.5.0"
s.add_development_dependency "rake", "10.3.2"
s.add_development_dependency "rspec", "3.0.0"
s.add_development_dependency "appraisal", "1.0.0"
s.add_development_dependency "bourne", "1.5.0"
s.add_development_dependency "rake", "10.3.2"
s.add_development_dependency "rspec", "3.0.0"
s.add_development_dependency "sqlite3", "1.3.9"
end
8 changes: 8 additions & 0 deletions gemfiles/rails_3.gemfile
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3"
gem "activesupport", "~> 3"

gemspec :path => "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_4.gemfile
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 4"
gem "activesupport", "~> 4"

gemspec :path => "../"
12 changes: 11 additions & 1 deletion spec/lib/allowed/limit_spec.rb
Expand Up @@ -30,7 +30,17 @@
it "adds validation callback" do
subject.allow(limit, options)

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

it "only calls validation callback on create" do
instance = subject.new
instance.stubs(:validate_throttles)

instance.save
instance.save

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

it "adds after rollback callback" do
Expand Down
16 changes: 13 additions & 3 deletions spec/support/have_callback.rb
@@ -1,10 +1,20 @@
RSpec::Matchers.define :have_callback do |type, name, options|
match do |record|
options ||= {}
callbacks = record.__send__(:"_#{type}_callbacks")
callbacks.any? do |callback|
callback.raw_filter == name &&
(options[:kind].nil? || callback.kind == options[:kind]) &&
(options[:on].nil? || callback.options[:on] == options[:on])
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
end
end
end

0 comments on commit a5fcd74

Please sign in to comment.