Skip to content

Instantly share code, notes, and snippets.

@costa
Last active December 11, 2015 10:48
Show Gist options
  • Save costa/4589368 to your computer and use it in GitHub Desktop.
Save costa/4589368 to your computer and use it in GitHub Desktop.
a model object's attributes stripper (for use in Rails 3.2+ controller specs), a place to put this: spec/support/accessible_attributes.rb
def accessible_attributes(obj, role = :default)
HashWithIndifferentAccess.new(obj.attributes.slice(*obj.class.attr_accessible[role].to_a))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment