I've written a story and I run into a snag.<br>I've written the create_forum method and told it to set the id to 1<br>but when it creates the forum the id is autoincremented. <br>My forums table is empty but the id keeps incrementing the newest record on creation.
<br>When I run the story it comes out as something like 59 which fails my story because I'm asking it to look at /forums/1<br><br>I thought of using my named routes instead of specifying the path as a string.<br>That worked up until the point when I reached:
<br><br>When "creating a new topic titled", "Nicks Mom" do |title|<br> post topics(@forum, ??? ), :topic => { :title => title, :body => "She is teh hotZ!" }<br>end<br><br>The problem was since its a nested routed I couldn't complete the post request without specifying the topic_id.
<br>But since the topic hasn't been created yet their is no way (that I know of) to pass the id since I don't know what it will be.<br><br>I would think the better practice is to state the paths as strings instead of using the nested routes.
<br><br><br><br>require File.join(File.dirname(__FILE__), "helper")<br><br>Story "User creates a new topic", %{<br> As a user<br> I want to create a new topic<br> So that I can dicuss Nick's Mom
<br> }, :type => RailsStory do<br> <br> Scenario "Successfully create a new topic in the 'General' forum" do<br> <br> Given "a user named", "Jon" do |login| <br> @user = create_user login
<br> end<br> Given "a forum named", "General" do |name|<br> @forum = create_forum name<br> puts @<a href="http://forum.id">forum.id</a><br> end<br> <br> And "user logged in successfully and was redirect to", "/" do |path|
<br> post "/session/create", :login => "Jon", :password => "your_momma"<br> response.should redirect_to("/")<br> end<br> <br> And "user is looking at", "/forums/1" do |path|
<br> get path<br> response.should be_success<br> end<br> <br> When "creating a new topic titled", "Nicks Mom" do |title|<br> post "/forums/1/topics/1/create", :topic => { :id => 1, :title => title, :body => "She is teh hotZ!" }
<br> end<br> <br> Then "user should be redirected to", "/forums/1/topics/1" do |path|<br> get path <br> response.should be_success<br> end<br> <br> end<br> <br> Scenario "Failed creating a new topic due to blank fields" do; end
<br> Scenario "Sticky a new thread" do; end<br> Scenario "Annoucment as a new thread" do; end<br>end<br> <br>def create_user(login)<br> user = User.create!(<br> :login => login, <br> :email => "
<a href="mailto:your@momma.com">your@momma.com</a>", <br> :password => "your_momma",<br> :password_confirmation => "your_momma",<br> :display_name => "Jon")<br> user<br>
end<br><br>def create_forum(name)<br> forum = Forum.create!(<br> :id => 1,<br> :name => name,<br> :description => "Everything from the latest gossip to the coolest youtube videos.")<br> forum
<br>end<br><br><br>How do I stop the incrementing?<br>