I'm new to unit testing and Rails in general. I've decided to build my
projects in a TDD manner, but this has left me with some early
questions.
I have this test written out:

describe User do
it "should add user to team" do
team = Team.create(:name => "Tigers")
akash = User.create(:name => "Akash")
akash.teams << team
akash.memberships.size.should == 1
john = User.create(:name => "John")
john.buddyup_with(akash)
john.memberships.size.should == 1
akash.buddys.should include(john)
end
end

Ideally, users may join many teams, and teams may have many members. If
a user is paired up with another user through "buddyup", those users
will share all of the same teams.
I've started on the User model, but I'm lost at this point. Can
somebody help me out? Here's what I have so far:

class User < ActiveRecord::Base
has_and_belongs_to_many :teams
validates_presence_of :name
end

class Team < ActiveRecord::Base
has_and_belongs_to_many :teams
validates_presence_of :name
end

All I want to do is pass the test, further functionality will be added
later.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tankard at Oct 26, 2011 at 11:58 am
    class Team < ActiveRecord::Base
    has_and_belongs_to_many :teams
    validates_presence_of :name
    end

    I suppose you mean :users instead of :teams
    On Oct 24, 8:12 am, Loff Stoff wrote:
    I'm new to unit testing and Rails in general.  I've decided to build my
    projects in a TDD manner, but this has left me with some early
    questions.
    I have this test written out:

    describe User do
    it "should add user to team" do
    team = Team.create(:name => "Tigers")
    akash = User.create(:name => "Akash")
    akash.teams << team
    akash.memberships.size.should == 1
    john = User.create(:name => "John")
    john.buddyup_with(akash)
    john.memberships.size.should == 1
    akash.buddys.should include(john)
    end
    end

    Ideally, users may join many teams, and teams may have many members.  If
    a user is paired up with another user through "buddyup", those users
    will share all of the same teams.
    I've started on the User model, but I'm lost at this point.  Can
    somebody help me out?  Here's what I have so far:

    class User < ActiveRecord::Base
    has_and_belongs_to_many :teams
    validates_presence_of :name
    end

    class Team < ActiveRecord::Base
    has_and_belongs_to_many :teams
    validates_presence_of :name
    end

    All I want to do is pass the test, further functionality will be added
    later.

    --
    Posted viahttp://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 24, '11 at 4:13a
activeOct 26, '11 at 11:58a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Loff Stoff: 1 post Tankard: 1 post

People

Translate

site design / logo © 2021 Grokbase