Skip to content

Commit

Permalink
5.1 compatibility (#67)
Browse files Browse the repository at this point in the history
* Make belongs_to optional for 5.1 compatibility

* Pass routes parameters as named params: argument

* Test againts activerecord 5.0 and 5.1.rc

Incompatible with 4 and older
  • Loading branch information
jmfederico authored and chrisdpeters committed May 31, 2017
1 parent 63da29d commit 87f2423
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ cache: bundler
sudo: false

rvm:
- 2.4.0-preview3
- 2.4.0
- 2.3.1
- 2.2.5

gemfile:
- gemfiles/ar_5_1.gemfile
- gemfiles/ar_5_0.gemfile

before_script:
- bundle exec rake -f spec/dummy/Rakefile db:schema:load
4 changes: 2 additions & 2 deletions draftsman.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ['lib']

s.add_dependency 'activerecord', ['>= 3.0', '< 5.1']
s.add_dependency 'activerecord', ['>= 5.0', '< 5.2']

s.add_development_dependency 'rake'
s.add_development_dependency 'railties', ['>= 3.0', '< 5.1']
s.add_development_dependency 'railties', ['>= 5.0', '< 5.2']
s.add_development_dependency 'sinatra', '~> 1.0'
s.add_development_dependency 'rspec-rails', '~> 3.5'

Expand Down
6 changes: 6 additions & 0 deletions gemfiles/ar_5_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gemspec path: '../'

gem 'activerecord', '~> 5.0.0'
gem 'railties', '~> 5.0.0'
6 changes: 6 additions & 0 deletions gemfiles/ar_5_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gemspec path: '../'

gem 'activerecord', '~> 5.1.0.rc2'
gem 'railties', '~> 5.1.0.rc2'
2 changes: 1 addition & 1 deletion lib/draftsman/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def has_drafts(options = {})
self.trashed_at_attribute_name = options[:trashed_at] || :trashed_at

# `belongs_to :draft` association
belongs_to(self.draft_association_name, class_name: self.draft_class_name, dependent: :destroy)
belongs_to(self.draft_association_name, class_name: self.draft_class_name, dependent: :destroy, optional: true)

# Scopes
scope :drafted, -> (referenced_table_name = nil) {
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/informants_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

describe 'update' do
before { put :update, id: trashable.id }
before { put :update, params: { id: trashable.id } }
subject { Draftsman::Draft.last }

it 'records `ip` from custom `info_for_draftsman`' do
Expand All @@ -31,7 +31,7 @@
end

describe 'destroy' do
before { delete :destroy, id: trashable.id }
before { delete :destroy, params: { id: trashable.id } }
subject { Draftsman::Draft.last }

it 'records `ip` from custom `info_for_draftsman`' do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

describe 'update' do
before { put :update, id: trashable.id }
before { put :update, params: { id: trashable.id } }
subject { return Draftsman::Draft.last }

it 'records user name via `user_for_draftsman`' do
Expand All @@ -22,7 +22,7 @@
end

describe 'destroy' do
before { delete :destroy, id: trashable.id }
before { delete :destroy, params: { id: trashable.id } }
subject { return Draftsman::Draft.last }

it 'records user name via `user_for_draftsman`' do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/whodunnits_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end

describe 'update' do
before { put :update, id: trashable.id }
before { put :update, params: { id: trashable.id } }
subject { Draftsman::Draft.last }

it 'records `current_user` via `user_for_draftsman' do
Expand All @@ -23,7 +23,7 @@
end

describe 'destroy' do
before { delete :destroy, id: trashable.id }
before { delete :destroy, params: { id: trashable.id } }
subject { Draftsman::Draft.last }

it 'records `current_user` via `user_for_draftsman' do
Expand Down

0 comments on commit 87f2423

Please sign in to comment.