Skip to content

Commit

Permalink
Mass-assignment problem fixed.
Browse files Browse the repository at this point in the history
Depending on ActiveRecord configuration, massive assignment might be
disabled for models which do not specify explicit attr_accessible or
attr_protected.  This commit removes mass-assignments from friend model.
  • Loading branch information
skalee committed Aug 23, 2012
1 parent 1afd332 commit f436251
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/amistad/active_record_friend_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module ActiveRecordFriendModel
# suggest a user to become a friend. If the operation succeeds, the method returns true, else false
def invite(user)
return false if user == self || find_any_friendship_with(user)
Amistad.friendship_class.new(:friendable_id => self.id, :friend_id => user.id).save
Amistad.friendship_class.new{ |f| f.friendable = self ; f.friend = user }.save
end

# approve a friendship invitation. If the operation succeeds, the method returns true, else false
Expand Down
4 changes: 4 additions & 0 deletions spec/activerecord/friend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
before(:all) do
reload_environment
User = Class.new(ActiveRecord::Base)

ActiveSupport.on_load(:active_record) do
attr_accessible(nil)
end
end

it_should_behave_like "friend with parameterized models" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def create_users(friend_model)
friend_model.delete_all
%w(John Jane David James Peter Mary Victoria Elisabeth).each do |name|
instance_variable_set("@#{name.downcase}".to_sym, friend_model.create(:name => name))
instance_variable_set("@#{name.downcase}".to_sym, friend_model.create{ |fm| fm.name = name})
end
end

Expand Down

0 comments on commit f436251

Please sign in to comment.