27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Listing 8.22 db/seeds.rb<br />

Seed data<br />

admin_user = User.create(:email => "admin@ticketee.com",<br />

:password => "password")<br />

admin_user.admin = true<br />

admin_user.confirm!<br />

Now run bin/cucumber features/seed.feature to ensure that you can sign in as this<br />

user. If you can, you should see the step passing and the next step failing:<br />

And I am signed in as "admin@ticketee.com"<br />

Then I should see "Ticketee Beta"<br />

Failed assertion, no message given. (MiniTest::Assertion)<br />

To get this last step of the scenario to pass, you must add the project to db/seeds.rb by<br />

putting this line in there:<br />

Project.create(:name => "Ticketee Beta")<br />

Your entire seeds file should look like the following listing.<br />

Listing 8.23 db/seeds.rb<br />

admin_user = User.create(:email => "admin@ticketee.com",<br />

:password => "password")<br />

admin_user.admin = true<br />

admin_user.confirm!<br />

Project.create(:name => "Ticketee Beta")<br />

This is all you need to get this feature to pass. Let’s run it now with bin/cucumber<br />

features/seed.feature to make sure:<br />

1 scenario (1 passed)<br />

3 steps (3 passed)<br />

Great! With this seeds file, you now have data to put in the database so you can bootstrap<br />

your application. Let’s run rake db:seed to load this data. Start your application’s<br />

server by typing rails server into a terminal, and then go to your server at<br />

http://localhost:3000 in your browser. Sign in as the admin user using the same email<br />

and password you set up in your seeds file. You should see the display shown in<br />

figure 8.6.<br />

When you’re signed in as a user, you should be<br />

able to do everything from creating a new ticket<br />

to creating a new user and setting up user permissions.<br />

Go ahead and play around with what you’ve<br />

created so far.<br />

When you’re done playing, run rake<br />

cucumber:ok spec for the final time this chapter: Figure 8.6 What admins see<br />

211

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!