mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-06 14:56:35 -04:00
wrote migration to add test users, fixed tests
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
class Garden < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
attr_accessible :name, :slug, :user_id
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class CreateGardens < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :gardens do |t|
|
||||
t.string :name, :null => false
|
||||
t.integer :user_id, :null => false
|
||||
t.integer :user_id
|
||||
t.string :slug, :null => false
|
||||
|
||||
t.timestamps
|
||||
|
||||
19
db/migrate/20121105035239_setup_test_users.rb
Normal file
19
db/migrate/20121105035239_setup_test_users.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class SetupTestUsers < ActiveRecord::Migration
|
||||
def up
|
||||
if Rails.env.development? or Rails.env.test?
|
||||
(1..3).each do |i|
|
||||
@user = User.create(:username => "test#{i}", :email => "test#{i}@example.com", :password => "password#{i}")
|
||||
@user.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
if Rails.env.development? or Rails.env.test?
|
||||
(1..3).each do |i|
|
||||
@user = User.find_by_username("test#{i}")
|
||||
@user.try(:destroy)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121105032913) do
|
||||
ActiveRecord::Schema.define(:version => 20121105035239) do
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
t.string "system_name", :null => false
|
||||
@@ -26,7 +26,7 @@ ActiveRecord::Schema.define(:version => 20121105032913) do
|
||||
|
||||
create_table "gardens", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "user_id"
|
||||
t.string "slug", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
|
||||
@@ -24,7 +24,7 @@ describe GardensController do
|
||||
# Garden. As you add validations to Garden, be sure to
|
||||
# update the return value of this method accordingly.
|
||||
def valid_attributes
|
||||
{}
|
||||
{:name => 'My Garden'}
|
||||
end
|
||||
|
||||
# This should return the minimal set of values that should be in the session
|
||||
|
||||
10
spec/migrations/set_up_test_users.spec
Normal file
10
spec/migrations/set_up_test_users.spec
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'test users' do
|
||||
it 'should have 3 test users' do
|
||||
(1..3).each do |i|
|
||||
@user = User.find_by_username("test#{i}")
|
||||
@user.email.should == "test#{i}@example.com"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user