mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-21 06:24:22 -04:00
give each user a garden. note: tests broken!
This commit is contained in:
1 parent
77c2e83c64
commit
b39ee792b4
6 files changed
+39
-4
No files matched your search
@@ -1,7 +1,11 @@
|
||||
class Garden < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
friendly_id :garden_slug, use: :slugged
|
||||
|
||||
attr_accessible :name, :slug, :user_id
|
||||
belongs_to :user
|
||||
|
||||
def garden_slug
|
||||
"#{user.username}-#{name}"
|
||||
end
|
||||
end
|
||||
+2
-1
@@ -1,4 +1,6 @@
|
||||
class User < ActiveRecord::Base
|
||||
has_many :gardens
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
# :lockable, :timeoutable and :omniauthable
|
||||
@@ -24,5 +26,4 @@ class User < ActiveRecord::Base
|
||||
where(conditions).first
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
class GiveEachUserAGarden < ActiveRecord::Migration
|
||||
def up
|
||||
User.all.each do |user|
|
||||
garden = Garden.create(:name => 'My Garden', :user_id => user.id)
|
||||
garden.save!
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
User.all.each do |user|
|
||||
garden = Garden.find_by_name_and_user_id('My Garden', user.id)
|
||||
garden.try(:destroy)
|
||||
end
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121105035239) do
|
||||
ActiveRecord::Schema.define(:version => 20121105052119) do
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
t.string "system_name", :null => false
|
||||
|
||||
@@ -20,11 +20,14 @@ require 'spec_helper'
|
||||
|
||||
describe GardensController do
|
||||
|
||||
@user = User.create(:username => 'testuser', :email => 'testuser@example.com', :password => 'testuser' )
|
||||
@user.confirm!
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Garden. As you add validations to Garden, be sure to
|
||||
# update the return value of this method accordingly.
|
||||
def valid_attributes
|
||||
{:name => 'My Garden'}
|
||||
{:name => 'My Garden', :user_id => @user.id }
|
||||
end
|
||||
|
||||
# This should return the minimal set of values that should be in the session
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'new gardens' do
|
||||
it "should have 'my garden' for each user" do
|
||||
(1..3).each do |i|
|
||||
@user = User.find_by_username("test#{i}")
|
||||
@garden = Garden.find(:name => "My Garden", :user_id => @user.id)
|
||||
@garden.should_exist
|
||||
@garden.slug.should == "test#{i}-my-garden"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user