Skip to content
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

Use string values in AR finders #5

Merged
merged 1 commit into from
Apr 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/flip/database_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def switchable?
end

def switch! key, enable
@klass.find_or_initialize_by_key(key).update_attributes! enabled: enable
@klass.find_or_initialize_by_key(key.to_s).update_attributes! enabled: enable
end

def delete! key
@klass.find_by_key(key).try(:destroy)
@klass.find_by_key(key.to_s).try(:destroy)
end

private

def feature(definition)
@klass.find_by_key definition.key
@klass.find_by_key definition.key.to_s
end

end
Expand Down
6 changes: 3 additions & 3 deletions spec/database_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@

describe "#switch!" do
it "can switch a feature on" do
model_klass.should_receive(:find_or_initialize_by_key).with(:one).and_return(disabled_record)
model_klass.should_receive(:find_or_initialize_by_key).with('one').and_return(disabled_record)
disabled_record.should_receive(:update_attributes!).with(enabled: true)
strategy.switch! :one, true
end
it "can switch a feature off" do
model_klass.should_receive(:find_or_initialize_by_key).with(:one).and_return(enabled_record)
model_klass.should_receive(:find_or_initialize_by_key).with('one').and_return(enabled_record)
enabled_record.should_receive(:update_attributes!).with(enabled: false)
strategy.switch! :one, false
end
end

describe "#delete!" do
it "can delete a feature record" do
model_klass.should_receive(:find_by_key).with(:one).and_return(enabled_record)
model_klass.should_receive(:find_by_key).with('one').and_return(enabled_record)
enabled_record.should_receive(:try).with(:destroy)
strategy.delete! :one
end
Expand Down