Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created August 23, 2012 15:46
Show Gist options
  • Save equivalent/3437893 to your computer and use it in GitHub Desktop.
Save equivalent/3437893 to your computer and use it in GitHub Desktop.
FactoryGirl attributes_for giving only accessible attributes
describe SomeModel do
it do
p accessible_attributes_for(:contact)
end
end
#....
def assessable_attributes_for(resource)
if resource.is_a? Symbol
(FactoryGirl.build resource).attributes.symbolize_keys.reject { |key, value| !resource.to_s.humanize.constantize.attr_accessible[:default].collect { |attribute| attribute.to_sym }.include?(key) }
else
resource.attributes.symbolize_keys.reject { |key, value| !resource.class.attr_accessible[:default].collect { |attribute| attribute.to_sym }.include?(key) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment