Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
[T8-183] Allow to work with ApplicationRecord (#6)
Browse files Browse the repository at this point in the history
* Allow ApplicationRecord as the superclass also

* Bump version

* Needed for version bump
  • Loading branch information
snowblink authored Jan 16, 2019
1 parent d868b97 commit 54f38f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
active_record_deprecate_columns (0.2.0)
active_record_deprecate_columns (0.3.0)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record_deprecate_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

module ActiveRecordDeprecateColumns
def deprecate_column(column_name, with_block: nil, fallback: nil)
raise "You can only deprecate columns on the superclass" if self.superclass != ActiveRecord::Base
raise "You can only deprecate columns on the superclass" unless (self.superclass == ActiveRecord::Base || self.superclass == ApplicationRecord)

deprecated_columns << column_name.to_s

Expand Down
2 changes: 1 addition & 1 deletion lib/active_record_deprecate_columns/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveRecordDeprecateColumns
VERSION = "0.2.0"
VERSION = "0.3.0"
end
9 changes: 6 additions & 3 deletions spec/models.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class BrandNewObject < ActiveRecord::Base
class ApplicationRecord < ActiveRecord::Base;
self.abstract_class = true
end

class User < ActiveRecord::Base
class BrandNewObject < ApplicationRecord; end

class User < ApplicationRecord
attr_accessor :attribute
deprecate_column :nothing
deprecate_column :old_name, with_block: Proc.new { raise NoMethodError }
Expand All @@ -10,6 +13,6 @@ class User < ActiveRecord::Base
deprecate_column :with_block_and_fallback, with_block: Proc.new {|object| object.attribute = "SET" }, fallback: :attribute
end

class Vehicle < ActiveRecord::Base
class Vehicle < ApplicationRecord
deprecate_column :not_used, with_block: Proc.new { raise NoMethodError }
end

0 comments on commit 54f38f3

Please sign in to comment.