Skip to content

Commit

Permalink
Merge pull request #1 from spark-solutions/fix/specs_for_rails-6
Browse files Browse the repository at this point in the history
Fix/specs for rails 6
  • Loading branch information
damianlegawiec authored May 21, 2019
2 parents 0528651 + 47d87bd commit 22efcac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/acts_as_taggable_on/taggable/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def #{tag_type}_list=(new_tags)
parsed_new_list = ActsAsTaggableOn.default_parser.new(new_tags).parse
if self.class.preserve_tag_order? || parsed_new_list.sort != #{tag_type}_list.sort
set_attribute_was('#{tag_type}_list', #{tag_type}_list)
if Rails.version < "6.0.0.beta1"
set_attribute_was('#{tag_type}_list', #{tag_type}_list)
else
duplicated_mutations_from_database.change_to_attribute('#{tag_type}_list')
end
write_attribute("#{tag_type}_list", parsed_new_list)
end
Expand All @@ -65,6 +70,17 @@ def all_#{tags_type}_list
def dirtify_tag_list(tagging)
attribute_will_change! tagging.context.singularize+"_list"
end
def duplicated_mutations_from_database
unless defined?(@mutations_from_database)
@mutations_from_database = nil
end
@mutations_from_database ||= if defined?(@attributes)
ActiveModel::AttributeMutationTracker.new(@attributes)
else
NullMutationTracker.instance
end
end
RUBY
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/acts_as_taggable_on/dirty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
it 'should show changes of freshly initialized dirty object' do
taggable = TaggableModel.find(@taggable.id)
taggable.tag_list = 'one'
expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
if Rails.version >= "6.0.0.beta1"
expect(taggable.changes).to eq({'tag_list' => [nil, ['one']]})
else
expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
end
end

if Rails.version >= "5.1"
Expand Down

0 comments on commit 22efcac

Please sign in to comment.