Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6115823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:08:10+00:00 2026-05-23T15:08:10+00:00

I use datamapper and postgres for my ror application, in my models i have

  • 0

I use datamapper and postgres for my ror application, in my models i have such associations:

#/models/account.rb
 has n, :transfers_out, "Transfer", :child_key => [ :account_from_id ]  
 has n, :transfers_in, "Transfer", :child_key => [ :account_to_id ]  

#/models/transfer.rb
 belongs_to :account_from, "Account", :child_key => [:account_from_id], :required => true
 belongs_to :account_to, "Account",   :child_key => [:account_to_id], :required => false

Now i need to test in rspec by using factory girl. So, I’ve wrote this:

#/factories/account.rb
Factory.define :account do |f|
  f.transfers_out {|transfer| [transfer.association(:transfer)]}
  f.transfers_in  {|transfer| [transfer.association(:transfer)]}
  f.amount "0"
end

  Factory.define :account_big, :class => :account do |f|
    f.name "MyMillionDollarPresent"
    f.amount "10000"
  end

Factory.define :account_small, :class => :account do |f|
  f.name "PoorHomo"
  f.amount "100"
end 

and little transfer factory

Factory.define :transfer do |f|
f.id "1"
f.comment  "payment"
f.status  "proposed"
f.amount "0"
end

So, I’ve tried to test creation of transfer from account:

    describe Transfer do

  before(:each) do
    @account_big = Factory(:account_big)
    @account_small = Factory(:account_small)
    @transfer = Factory(:transfer)
  end

  it "should debit buyer" do
    @buyer = @account_big
    @buyer.transfers_out = @transfer
    @transfer.amount = 3000
    @buyer.amount -= @transfer.amount
    @buyer.amount.should == 7000
  end

But that results me with failed test:

 1) Transfer should debit buyer
     Failure/Error: @buyer.transfers_out = @transfer
     TypeError:
       can't convert Transfer into Array
     # ./spec/models/transfer_spec.rb:15:in `block (2 levels) in <top (required)>'

Soo, what should i do and how should i declare the association with the child key in this situation? Would be thankful for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:08:11+00:00Added an answer on May 23, 2026 at 3:08 pm

    @buyer.transfers_out is an array and @transfer is a single object. If you want to make an array with one element you should use @buyer.transfers_out = [ @transfer ] or something like @buyer.transfers_out << @transfer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with DataMapper and trying to use associations between models Project and Task.
need to use a good PHP ORM that has elements of Datamapper and I
I am trying to install, and use, the datamapper gem in my Sinatra application.
I was looking at DataMapper , which appeared at first glance to use the
Use case: 3rd party application wants to programatically monitor a text file being generated
How to use list/array as property in DataMapper on Jruby on Google AppEngine?
This regards the ruby ORM library DataMapper . This wiki describes how to use
Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection
Is it possible to use concurrent databases in one rails application? With AR I
My question is about memory use and objects in actionscript 2. If I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.