-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Rails 3 serialized attributes #14
Conversation
spec/spec_helper.rb
Outdated
@@ -25,6 +26,8 @@ class Fake < ActiveRecord::Base | |||
before_save :before_save_callback | |||
|
|||
belongs_to :belonger | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
Doubt that it would require version checks. Serialized columns should work irrespective of whichever version we're on right? |
@ritikesh yep, sounds right. Let's check if it is really saved in specs |
@einzige when I ran specs, it ran with 0 failures. How about you? |
@ritikesh 0 failures, but we need to make sure a serialized column gets saved. For instance: it 'updates serialized column' do
expect do
fake.config = {one: :two}
fake.sneaky_save!
end.to change { fake.reload.config }.from(nil).to(one: :two)
end |
spec/spec_helper.rb
Outdated
@@ -25,6 +26,8 @@ class Fake < ActiveRecord::Base | |||
before_save :before_save_callback | |||
|
|||
belongs_to :belonger | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
spec/lib/sneaky_save_spec.rb
Outdated
expect(subject.sneaky_save).to eq(true) | ||
subject.reload | ||
expect(subject.name).to eq("new name") | ||
expect(subject.sneaky_save).to eq(true) | ||
expect(subject.config).to eq({test: "test"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { missing.
Redundant curly braces around a hash parameter.
Space inside } missing.
@@ -71,10 +78,11 @@ | |||
|
|||
it "stores attributes in database" do | |||
subject.name = "new name" | |||
subject.config = {test: "test"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { missing.
Space inside } missing.
spec/lib/sneaky_save_spec.rb
Outdated
|
||
it "updates serialized column" do | ||
expect do | ||
fake.config = {one: :two} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 3) spaces for indentation.
Space inside { missing.
Space inside } missing.
|
||
# Serialize values for rails3 before updating | ||
unless sneaky_new_rails? | ||
serialized_fields = self.class.serialized_attributes.keys & changed_attributes.keys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [89/80]
@ritikesh
Going forward, let's have our updates separated in commits.
For a spec, you'll need to update
spec/spe_helper.rb
where you'll find a test class called "Fake", just add a new column to it and serialize the way you did in your app.It may also require you to add conditional spec / code depending on a currently running rails/AR version, eg:
if ActiveRecord.version < 4 then add serialization, run this spec