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

Commit

Permalink
Merge pull request #5 from G5/fix_less_than_rails_4-2_issue
Browse files Browse the repository at this point in the history
Fix issue when deleting keys.
  • Loading branch information
ramontayag committed Apr 9, 2015
2 parents 9703b2e + 99f8bd1 commit 335cd98
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ spec/dummy/tmp/
spec/dummy/.sass-cache
spec/dummy/config/database.yml
tmp
gemfiles/*.lock
7 changes: 7 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appraise "rails_4.1_and_below" do
gem "rails", "4.1"
end

appraise "rails_4.2_and_above" do
gem "rails", "4.2"
end
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TBA

- Fix bug when deleting keys

# 1.0.0

- Expose class method `storext_definitions` to list defined Storext attributes
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ gemspec
# your gem to rubygems.org.

gem 'pry'

gem 'appraisal'
9 changes: 9 additions & 0 deletions gemfiles/rails_4.1_and_below.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "pry"
gem "appraisal"
gem "rails", "4.1"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_4.2_and_above.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "pry"
gem "appraisal"
gem "rails", "4.2"

gemspec :path => "../"
3 changes: 3 additions & 0 deletions lib/storext/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module InstanceMethods

def destroy_key(column, attr)
new_value = send(column)
if Rails.gem_version < Gem::Version.new("4.2.0")
new_value = send(column).dup
end
new_value.delete(attr.to_s)
send("#{column}=", new_value)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/storext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@
book.reload
expect(book.data).to have_key("author")
end

it "updates the changes when saved" do
book = Book.create
book.data = {'hulla' => 'balloo'}
book.save
expect(book.data['hulla']).to eq 'balloo'
book.destroy_key(:data, :hulla)
book.save
book.reload
expect(book.data).to_not have_key("hulla")
end
end

describe ".destroy_keys" do
Expand Down

0 comments on commit 335cd98

Please sign in to comment.