Home arrow Ruby-on-Rails arrow Testing a Book Emporium Application
RUBY-ON-RAILS

Testing a Book Emporium Application


In this conclusion to a three-part series on how to do a project setup and proof of concept for a fictional bookstore on Ruby-on-Rails, we'll actually start the application for the first time and see how it functions. This article is excerpted from chapter one of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 30, 2010
TABLE OF CONTENTS:
  1. · Testing a Book Emporium Application
  2. · Starting Emporium for the First Time
  3. · How Does Ruby on Rails Work?
  4. · Modifying the Generated View
  5. · Creating the Layout
  6. · Creating a Style Sheet

print this article
SEARCH DEVARTICLES

Testing a Book Emporium Application
(Page 1 of 6 )

Setting Up the Database User

Next, create the MySQL user that will be used when connecting to the database environments. This is done by executing the following commands:

$ mysql -u root
mysql> grant all on emporium_development.* to \
  'emporium'@'localhost' identified by 'hacked';

--------------------------------------------
Query OK, 0 rows affected (0.05 sec)
--------------------------------------------

mysql> grant all on emporium_test.* to \ 
  'emporium'@'localhost'
identified by 'hacked';

--------------------------------------------
Query OK, 0 rows affected (0.01 sec)
--------------------------------------------

Note that we created only one user but granted access to both environments, with thegrant allcommand. The first parameter,emporium_development.*, means we are giving all available privileges to the user. The second parameter,'emporium'@'localhost', consists of two parts: the username and the IP address or address the user is allowed to connect from separated by@. The third parameter,identified by 'hacked', assigns the passwordhackedto the user.

You can get a list of all users by executing the following SQL:

mysql> select host, user from mysql.user;

--------------------------------------------
+-----------+----------+
| host      | user     |
+-----------+----------+
| localhost | emporium |
| localhost | root     |
+-----------+----------+
2 rows in set (0.00 sec)
--------------------------------------------


Caution  Don’t give all available permissions to the MySQL user that will be used to connect to the production database. An application normally needs only select, insert, update, and delete privileges. For more information on the syntax of the grant command see http://dev.mysql.com/doc/refman/5.0/en/ grant.html.


Configuring Ruby on Rails to Use the Database

The information Ruby on Rails needs for connecting to the database is located in a configuration file that is written in a lightweight markup language called YAML, an acronym for “YAML Ain’t Markup Language.” Ruby on Rails favors YAML over XML because YAML is both easier to read and write than XML.

The configuration file,database.yml, is located in thedbfolder and was created for you when you ran therailscommand earlier in this chapter. The generated configuration template contains examples for MySQL, PostgreSQL, and SQLite. The MySQL configuration is enabled by default, and the other two database configurations are commented out.

Open the file and specify the database name and remove all of the text. Next, specify the database name, username, and password for the development and test environments, as shown in Listing 1-1.

Listing 1-1. Emporium Database Configuration

development:
  adapter: mysql
  database: emporium_development
  username: emporium
  password: hacked

test:
  adapter: mysql
  database: emporium_test
  username: emporium
  password: hacked

Save the configuration after you are finished editing it.


Tip  The database configuration for each Rails environment is located in one file,database.yml. The runtime configuration for the development, test, and production environments are defined in separate configuration files. You can see the differences between the environments by comparing thedevelopment.rb,test.rb, andproduction.rbfiles, which can be found in theconfig/environmentsfolder under the Rails application root. This is also where you should put the environment-specific configuration of your application.



blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials