Trying to come up with a nice DSL, but having some problems

I have three models in this small game I’m working on - the Game,
Players, and Turns. A Player should be able to rescue another Player
on any given turn. So it looks like this:

class Game
has_many :players
has_many :turns

def rescue_player§
t = turns.last
t.rescued = p

class Turn
belongs_to :rescued, :foreign_key => ‘rescued_id’, :class_name =>

class Player
belongs_to :game

def rescue_player§
game.rescue_player p

So what I want to do is be able to create a game object and do
something like this:

g = create_game # factory method in test_helper that just creates a
new random game
g.players.first.rescue_player g.players.last
assert_equal g.players.last, g.turns.last.rescued

Now if I just do that, the data gets saved in the database, but the
assert fails. This is because g != I can do a
g.reload right before the assert and then it works fine. I’m just not
quite sure what I need to do, because I think it’s pretty lame to have
to reload every time I do something like this. Also when I’m actually
using the code I won’t remember to call reload, as it’s just not
really a natural thing to do. Can anyone give me some advice on how
to create the DSL I want, without resorting to adding ugliness like
random reload calls?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs