0
votes

I'm new to rails and testing and have a problem with loading my fixtures.

payment.yml
payment:
  name: something
  amount: 1.5
  event: some_event
  user: some_user
  description: long text
  users: some_user, some_user2


users.yml
some_user:
  email: [email protected]   nick: name

some_user2:
  email: [email protected]
  nick: name

okey, so the problem is that when I'm doing the functionaltest for creating a payment

test "should create payment" do
assert_difference('Payment.count') do
  post :create, :payment => @payment.attributes
end

it just sends

< Payment id: nil, name: "something", amount: 1.5, event_id: 972288058, user_id: 63246679, created_at: "2010-11-05 19:56:53", updated_at: "2010-11-05 19:56:53", description: "long text" >

and not the users array with multiple users. I use the "user" to define who owns the payment and users (in a seperate join table) as a list of users sharing the payment.

Any idea what I'm doing wrong?

here is the model for payments

class Payment < ActiveRecord::Base
  has_many :comments, :as => :commentable, :dependent => :destroy
  belongs_to :event
  belongs_to :user
  has_and_belongs_to_many :users
end

1

1 Answers

1
votes

Can you put the model for payment? I had something similar and the problem was that the model was different. For example, if it's a ActiveRecord class, you have to check how it and its relationships. For example, if the event is actually an "event_id" that belongs_to an "event" class, then you should put something similar to this:

payment.yml
payment:
  name: something
  amount: 1.5
  event_id: 1
  user_id: 1
  ...
user.yml
   id: 1
   name: David Smith
   status: Branch Manager
  ...
event.yml
  id: 1
  name: overdraft charge