Skip to content

Commit

Permalink
Merge pull request medihack#9 from acmetech/master
Browse files Browse the repository at this point in the history
Specified a white list of attributes that can be set via mass-assignment.
  • Loading branch information
Eric Berry committed Mar 22, 2012
2 parents 1b16851 + 1bb7800 commit ead528b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/make_flaggable/flagging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module MakeFlaggable
class Flagging < ActiveRecord::Base
attr_accessible :flaggable, :flagger, :flag
belongs_to :flaggable, :polymorphic => true
belongs_to :flagger, :polymorphic => true
scope :with_flag, lambda { |flag| where(:flag => flag.to_s) }
Expand Down
4 changes: 4 additions & 0 deletions spec/models.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class Flagging < ActiveRecord::Base
attr_accessible :flaggable, :flagger, :flag
end

class FlaggableModel < ActiveRecord::Base
make_flaggable :favorite, :inappropriate
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/flagging_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe Flagging do
describe "attributes should be white listed" do
it { should allow_mass_assignment_of(:flaggable) }
it { should allow_mass_assignment_of(:flagger) }
it { should allow_mass_assignment_of(:flag) }
end
end

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'rspec'
require 'active_record'
require 'database_cleaner'
require 'support/be_accessible_matcher'

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
require 'make_flaggable'
Expand Down
8 changes: 8 additions & 0 deletions spec/support/be_accessible_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RSpec::Matchers.define :allow_mass_assignment_of do |attribute|
match do |response|
response.class.accessible_attributes.include?(attribute)
end
description { "be accessible :#{attribute}" }
failure_message_for_should { ":#{attribute} should be accessible" }
failure_message_for_should_not { ":#{attribute} should not be accessible" }
end

0 comments on commit ead528b

Please sign in to comment.