0

I am trying to learn rails following SAAS course in coursera.

I ran

rake db:migrate
db:test:prepare  

to create a test db and run some cucumber steps against it.

I need a way to insert some movies in the corresponding movie table in test .

I can see a scehma.rb in db folder, and also in models, there is just Movie table created by class Movie < ActiveRecord::Base , but nothing such created for test dbs ?

Where can I find the testDB creation files , how do I find all the table names in my DB . I dont even know the db name to run :

 SELECT * FROM dbname.sqlite_master WHERE type='table';

Also if there are some better/easier ways of doing this please share your experience. I expect the suggestions to be something that I can try in 5 mins and not spend debugging time to install a new gem etc, although you can mention them as an additional comment.

Thanks

codeObserver
  • 6,521
  • 16
  • 76
  • 121

1 Answers1

0

Db data (name and configure) for all environment (test, dev, prod) defines in config -> database.yml file. Like this:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
zishe
  • 10,665
  • 12
  • 64
  • 103
  • Thnks Alder for the pointer. So test.sqlit3 is the db name ? .. This didnt work for me sqlite> SELECT * FROM test.sqlit3.sqlite_master WHERE type='table'; Error: near ".": syntax error . How do I find the name of db and test tables – codeObserver Aug 12 '12 at 23:59
  • Different databases is a different files so you shouldn't use names of it. When you use rails console you use develoment database, so you can't select something from test db. What do you use for queries? Maybe aome sql editor or smth. – zishe Aug 13 '12 at 00:42
  • You can connect to test db `rails db test`. But I don't khow how to select columns. – zishe Aug 13 '12 at 00:54
  • I found `PRAGMA table_info(table_name);` I guess you it's only method [link](http://stackoverflow.com/questions/947215/how-to-get-a-list-of-column-names-on-sqlite3-iphone) – zishe Aug 13 '12 at 00:58