27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

to this:<br />

Seed data<br />

def permissions<br />

{<br />

"view" => "View",<br />

"create tickets" => "Create Tickets",<br />

"edit tickets" => "Edit Tickets",<br />

"delete tickets" => "Delete Tickets"<br />

}<br />

end<br />

By adding these two permissions here, you display the check boxes that should make<br />

your scenarios all green. Let’s run the feature with bin/cucumber features/assigning<br />

_permissions.feature to find out:<br />

4 scenarios (4 passed)<br />

72 steps (72 passed)<br />

How great are you? Two features with one blow. Awesome stuff.<br />

That’s the final piece of the authorization puzzle. You now have a way for admins<br />

to assign permissions to users. But does everything work? Here’s hoping! Let’s run<br />

rake cucumber:ok spec:<br />

44 scenarios (44 passed)<br />

448 steps (448 passed)<br />

# and<br />

26 examples, 0 failures, 11 pending<br />

Awesome! Let’s commit this:<br />

git add .<br />

git commit -m "Added creating, editing, updating and deleting<br />

tickets to assigning permissions interface"<br />

git push<br />

Although it’s great that you now have an interface for assigning permissions, you<br />

don’t have a way to do it without first having an admin user set up. You can set up an<br />

admin user manually through the console, or you can do it by creating seed data.<br />

8.9 Seed data<br />

Seed data is records created for the purpose of providing the minimal viable requirements<br />

to get an application running. Before Rails 2.2, many applications implemented<br />

such records through using plugins such as seed_fu, but since 2.2, seed data is<br />

built in.<br />

Seed data allows you to create records for your application to provide a usable base<br />

if you or anybody else wants to get set up with the application quickly and easily. For<br />

your application’s seed data, you’ll create an admin user and an example project.<br />

From there, anybody using the admin user will be able to perform all the functions of<br />

the application.<br />

Seed data lives under db/seeds.rb, and you can run this file by running rake<br />

db:seed. The code for this rake task is this:<br />

load Rails.root + "db/seeds.rb"<br />

209

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

Saved successfully!

Ooh no, something went wrong!