mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 03:02:43 -04:00
@@ -6,7 +6,8 @@ class Garden < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
def garden_slug
|
||||
"#{user.username}-#{name}"
|
||||
formatted_name = name.downcase.gsub(' ', '-')
|
||||
"#{user.username}-#{formatted_name}"
|
||||
end
|
||||
|
||||
def owner
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
%li{:class => first_garden ? 'active' : '' }
|
||||
- first_garden = false
|
||||
= link_to g.name, "#garden#{g.id}", 'data-toggle' => 'tab'
|
||||
%li= link_to 'New garden', '#garden_new', 'data-toggle' => 'tab'
|
||||
%li= link_to 'New Garden', '#garden_new', 'data-toggle' => 'tab'
|
||||
.tab-content
|
||||
- first_garden = true
|
||||
- @member.gardens.each do |g|
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
factory :crop do
|
||||
system_name "Magic bean"
|
||||
en_wikipedia_url "http://en.wikipedia.org/wiki/Magic_bean"
|
||||
|
||||
factory :tomato do
|
||||
system_name "Tomato"
|
||||
|
||||
6
spec/factories/garden.rb
Normal file
6
spec/factories/garden.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :garden do
|
||||
name 'My Garden'
|
||||
user
|
||||
end
|
||||
end
|
||||
9
spec/factories/planting.rb
Normal file
9
spec/factories/planting.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
FactoryGirl.define do
|
||||
factory :planting do
|
||||
garden
|
||||
crop
|
||||
planted_at Time.now
|
||||
quantity 3
|
||||
description "This is a *really* good plant."
|
||||
end
|
||||
end
|
||||
19
spec/factories/update.rb
Normal file
19
spec/factories/update.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
factory :update do
|
||||
subject "An Update"
|
||||
body "This is some text."
|
||||
user
|
||||
|
||||
# Markdown is allowed in updates
|
||||
factory :markdown_update do
|
||||
body "This is some **strong** text."
|
||||
end
|
||||
|
||||
# HTML isn't allowed in updates
|
||||
factory :html_update do
|
||||
body '<a href="http://evil.com">EVIL</a>'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,13 +1,25 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
factory :user do
|
||||
username "user1"
|
||||
password "password1"
|
||||
email "user1@example.com"
|
||||
username 'user1'
|
||||
password 'password1'
|
||||
email 'user1@example.com'
|
||||
tos_agreement true
|
||||
confirmed_at Time.now()
|
||||
|
||||
factory :confirmed_user do
|
||||
confirmed_at Time.now()
|
||||
factory :no_tos_user do
|
||||
tos_agreement false
|
||||
email 'notos@example.com'
|
||||
end
|
||||
|
||||
factory :unconfirmed_user do
|
||||
confirmed_at nil
|
||||
email 'confirmed@example.com'
|
||||
end
|
||||
|
||||
factory :long_name_user do
|
||||
username 'Marmaduke Blundell-Hollinshead-Blundell-Tolemache-Plantagenet-Whistlebinkie, 3rd Duke of Marmoset'
|
||||
email 'marmaduke@example.com'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,14 +2,12 @@ require 'spec_helper'
|
||||
|
||||
describe Garden do
|
||||
before :each do
|
||||
@user = mock_model(User)
|
||||
@user.stub!(:username).and_return("test1")
|
||||
@garden = Garden.new(:name => "my garden")
|
||||
@garden.user = @user
|
||||
@user = FactoryGirl.create(:user)
|
||||
@garden = FactoryGirl.create(:garden, :user => @user)
|
||||
end
|
||||
|
||||
it "should have a slug" do
|
||||
@garden.garden_slug.should == "test1-my garden"
|
||||
@garden.garden_slug.should == "user1-my-garden"
|
||||
end
|
||||
|
||||
it "should have an owner" do
|
||||
|
||||
@@ -3,38 +3,20 @@ require 'spec_helper'
|
||||
describe Planting do
|
||||
|
||||
before(:each) do
|
||||
@crop = Crop.create(
|
||||
:system_name => "Tomato",
|
||||
:en_wikipedia_url => "http://en.wikipedia.org/wiki/Tomato"
|
||||
)
|
||||
|
||||
@user = User.create!(
|
||||
:username => 'foo',
|
||||
:password => 'irrelevant',
|
||||
:email => 'foo@example.com',
|
||||
:tos_agreement => true
|
||||
)
|
||||
@user.confirm!
|
||||
|
||||
@garden = Garden.create(
|
||||
:user_id => @user.id,
|
||||
:name => 'bar'
|
||||
)
|
||||
|
||||
@planting = Planting.create(
|
||||
:garden_id => @garden.id,
|
||||
:crop_id => @crop.id
|
||||
)
|
||||
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@garden = FactoryGirl.create(:garden, :user => @user)
|
||||
@planting = FactoryGirl.create(:planting,
|
||||
:crop => @crop, :garden => @garden)
|
||||
end
|
||||
|
||||
it "generates an owner" do
|
||||
@planting.owner.should be_an_instance_of User
|
||||
@planting.owner.username.should match /^foo$/
|
||||
@planting.owner.username.should match /^user1$/
|
||||
end
|
||||
|
||||
it "generates a location" do
|
||||
@planting.location.should match /^foo's bar$/
|
||||
@planting.location.should match /^user1's My Garden$/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,26 +2,22 @@ require 'spec_helper'
|
||||
|
||||
describe Update do
|
||||
before(:each) do
|
||||
user = User.create! :username => "test", :password => "password",
|
||||
:email => "test@example.com", :tos_agreement => true
|
||||
user.confirm!
|
||||
@id = user.id
|
||||
@user = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
it "should be sorted in reverse order" do
|
||||
Update.create! :subject => "first entry", :body => "blah", :user_id => @id
|
||||
Update.create! :subject => "second entry", :body => "blah", :user_id => @id
|
||||
FactoryGirl.create(:update, :subject => 'first entry', :user => @user)
|
||||
FactoryGirl.create(:update, :subject => 'second entry', :user => @user)
|
||||
Update.first.subject.should == "second entry"
|
||||
end
|
||||
|
||||
it "should have a slug" do
|
||||
update = Update.create! :subject => "slugs are nasty",
|
||||
:body => "They leave slime everywhere", :user_id => @id
|
||||
time = update.created_at
|
||||
datestr = time.strftime("%Y%m%d")
|
||||
@update = FactoryGirl.create(:update, :user => @user)
|
||||
@time = @update.created_at
|
||||
@datestr = @time.strftime("%Y%m%d")
|
||||
# 2 digit day and month, full-length years
|
||||
# Counting digits using Math.log is not precise enough!
|
||||
datestr.length.should == 4 + time.year.to_s.size
|
||||
update.slug.should == "test-#{datestr}-slugs-are-nasty"
|
||||
@datestr.length.should == 4 + @time.year.to_s.size
|
||||
@update.slug.should == "#{@user.username}-#{@datestr}-an-update"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,12 +4,7 @@ describe 'user' do
|
||||
|
||||
context 'valid user' do
|
||||
before(:each) do
|
||||
@user = User.create(
|
||||
:email => "example@example.com",
|
||||
:username => "someone",
|
||||
:password => "irrelevant",
|
||||
:tos_agreement => true
|
||||
)
|
||||
@user = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
it 'should save a basic user' do
|
||||
@@ -18,10 +13,10 @@ describe 'user' do
|
||||
|
||||
it 'should be fetchable from the database' do
|
||||
@user.save
|
||||
@user2 = User.find_by_email('example@example.com')
|
||||
@user2.username.should == "someone"
|
||||
@user2.email.should == "example@example.com"
|
||||
@user2.slug.should == "someone"
|
||||
@user2 = User.find_by_email('user1@example.com')
|
||||
@user2.username.should == "user1"
|
||||
@user2.email.should == "user1@example.com"
|
||||
@user2.slug.should == "user1"
|
||||
@user2.encrypted_password.should_not be_nil
|
||||
end
|
||||
|
||||
@@ -31,18 +26,14 @@ describe 'user' do
|
||||
end
|
||||
|
||||
it 'should stringify as the username' do
|
||||
@user.to_s.should == 'someone'
|
||||
"#{@user}".should == 'someone'
|
||||
@user.to_s.should == 'user1'
|
||||
"#{@user}".should == 'user1'
|
||||
end
|
||||
end
|
||||
|
||||
context 'no TOS agreement' do
|
||||
before(:each) do
|
||||
@user = User.create(
|
||||
:email => "example@example.com",
|
||||
:username => "someone",
|
||||
:password => "irrelevant"
|
||||
)
|
||||
@user = FactoryGirl.build(:no_tos_user)
|
||||
end
|
||||
|
||||
it "should refuse to save a user who hasn't agreed to the TOS" do
|
||||
|
||||
@@ -14,7 +14,7 @@ describe "crops/edit" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:confirmed_user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ describe "crops/new" do
|
||||
context "logged in" do
|
||||
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:confirmed_user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
@@ -11,17 +11,9 @@ describe "gardens/edit" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = User.create(:email => "growstuff@example.com",
|
||||
:password => "irrelevant")
|
||||
@user.confirm!
|
||||
@user = FactoryGirl.create(:user)
|
||||
sign_in @user
|
||||
|
||||
@garden = assign(:garden, stub_model(Garden,
|
||||
:name => "MyString",
|
||||
:user_id => @user.id,
|
||||
:slug => "MyString"
|
||||
))
|
||||
|
||||
@garden = assign(:garden, FactoryGirl.create(:garden, :user => @user))
|
||||
render
|
||||
end
|
||||
|
||||
|
||||
@@ -2,25 +2,17 @@ require 'spec_helper'
|
||||
|
||||
describe "gardens/index" do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
assign(:gardens, [
|
||||
stub_model(Garden,
|
||||
:name => "Name",
|
||||
:user_id => "",
|
||||
:slug => "Slug"
|
||||
),
|
||||
stub_model(Garden,
|
||||
:name => "Name",
|
||||
:user_id => "",
|
||||
:slug => "Slug"
|
||||
)
|
||||
FactoryGirl.create(:garden, :user => @user),
|
||||
FactoryGirl.create(:garden, :user => @user)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of gardens" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Slug".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "My Garden".to_s, :count => 2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,11 +2,7 @@ require 'spec_helper'
|
||||
|
||||
describe "gardens/new" do
|
||||
before(:each) do
|
||||
assign(:garden, stub_model(Garden,
|
||||
:name => "MyString",
|
||||
:user_id => "",
|
||||
:slug => "MyString"
|
||||
).as_new_record)
|
||||
assign(:garden, FactoryGirl.create(:garden))
|
||||
end
|
||||
|
||||
it "renders new garden form" do
|
||||
|
||||
@@ -2,17 +2,8 @@ require 'spec_helper'
|
||||
|
||||
describe "gardens/show" do
|
||||
before(:each) do
|
||||
@user = User.create(
|
||||
:username => 'foo',
|
||||
:email => 'foo@example.com',
|
||||
:password => 'irrelevant',
|
||||
:tos_agreement => true
|
||||
)
|
||||
@user.confirm!
|
||||
@garden = assign(:garden, stub_model(Garden,
|
||||
:name => "Garden Name",
|
||||
:user_id => @user.id
|
||||
))
|
||||
@user = FactoryGirl.create(:user)
|
||||
@garden = assign(:garden, FactoryGirl.create(:garden, :user => @user))
|
||||
end
|
||||
|
||||
context 'logged out' do
|
||||
|
||||
@@ -3,18 +3,8 @@ require 'spec_helper'
|
||||
describe "members/index" do
|
||||
before(:each) do
|
||||
assign(:members, [
|
||||
User.create!(
|
||||
:username => "Marmaduke Blundell-Hollinshead-Blundell-Tolemache-Plantagenet-Whistlebinkie, 3rd Duke of Marmoset",
|
||||
:password => "ilikehorses",
|
||||
:email => "binky@example.com",
|
||||
:tos_agreement => true
|
||||
),
|
||||
User.create!(
|
||||
:username => "bob",
|
||||
:password => "password",
|
||||
:email => "bob@example.com",
|
||||
:tos_agreement => true
|
||||
)
|
||||
FactoryGirl.create(:user),
|
||||
FactoryGirl.create(:long_name_user)
|
||||
])
|
||||
render
|
||||
end
|
||||
@@ -24,10 +14,10 @@ describe "members/index" do
|
||||
end
|
||||
|
||||
it "does not truncate short names" do
|
||||
rendered.should contain "bob"
|
||||
rendered.should_not contain "bob..."
|
||||
rendered.should contain "user1"
|
||||
rendered.should_not contain "user1..."
|
||||
end
|
||||
|
||||
|
||||
it "counts the number of members" do
|
||||
rendered.should contain "Displaying 2 members"
|
||||
end
|
||||
@@ -35,5 +25,5 @@ describe "members/index" do
|
||||
it "contains two gravatar icons" do
|
||||
assert_select "img", :src => /gravatar\.com\/avatar/, :count => 2
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "members/show" do
|
||||
|
||||
before(:each) do
|
||||
@member = User.create!(
|
||||
:username => "pie",
|
||||
:password => "steak&kidney",
|
||||
:email => "steak-and-kidney@pie.com",
|
||||
:tos_agreement => true
|
||||
)
|
||||
@member = FactoryGirl.create(:user)
|
||||
@time = @member.created_at
|
||||
@member.gardens.create(:name => 'My Garden', :user_id => @member.id)
|
||||
|
||||
# need @garden to render the page
|
||||
@garden = Garden.new
|
||||
render
|
||||
end
|
||||
@@ -23,4 +20,32 @@ describe "members/show" do
|
||||
assert_select "img", :src => /gravatar\.com\/avatar/
|
||||
end
|
||||
|
||||
context "no gardens" do
|
||||
it "shouldn't mention the name of a garden" do
|
||||
rendered.should_not contain "My Garden"
|
||||
end
|
||||
end
|
||||
|
||||
context "signed in user" do
|
||||
before(:each) do
|
||||
sign_in @member
|
||||
render
|
||||
end
|
||||
|
||||
it "contains a 'New Garden' link" do
|
||||
assert_select "a[href=#garden_new]", :text => "New Garden"
|
||||
end
|
||||
end
|
||||
|
||||
context "user has a garden" do
|
||||
before(:each) do
|
||||
@member.gardens.create(:name => 'My Garden', :user_id => @member.id)
|
||||
render
|
||||
end
|
||||
|
||||
it "displays a garden, if the user has one" do
|
||||
rendered.should contain "My Garden"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -18,20 +18,12 @@ describe "plantings/edit" do
|
||||
)
|
||||
@wrong_user.confirm!
|
||||
|
||||
@garden = assign(:garden, stub_model(Garden,
|
||||
:id => 1,
|
||||
:user => @right_user,
|
||||
:name => "Blah"
|
||||
))
|
||||
@planting = assign(:planting, stub_model(Planting,
|
||||
:garden_id => 1,
|
||||
:crop_id => 1,
|
||||
:quantity => 1,
|
||||
:description => "MyText"
|
||||
))
|
||||
@crop = FactoryGirl.create(:crop)
|
||||
@garden = FactoryGirl.create(:garden, :user => @right_user)
|
||||
|
||||
assign(:crop, Crop.new)
|
||||
assign(:garden, Garden.new)
|
||||
@planting = assign(:planting,
|
||||
FactoryGirl.create(:planting, :garden => @garden, :crop => @crop)
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
@@ -61,9 +53,6 @@ describe "plantings/edit" do
|
||||
end
|
||||
|
||||
it "renders the edit planting form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form", :action => plantings_path(@planting), :method => "post" do
|
||||
assert_select "select#planting_garden_id", :name => "planting[garden_id]"
|
||||
assert_select "select#planting_crop_id", :name => "planting[crop_id]"
|
||||
|
||||
@@ -2,38 +2,20 @@ require 'spec_helper'
|
||||
|
||||
describe "plantings/index" do
|
||||
before(:each) do
|
||||
@user = assign(:user, stub_model(User,
|
||||
:id => 23,
|
||||
:username => 'blah',
|
||||
:password => 'blahblah',
|
||||
:tos_agreement => true
|
||||
))
|
||||
@garden = assign(:garden, stub_model(Garden,
|
||||
:id => 42,
|
||||
:user => @user,
|
||||
:name => "My Awesome Allotment"
|
||||
))
|
||||
@crop = assign(:crop, stub_model(Crop,
|
||||
:id => 98,
|
||||
:system_name => "Tomato"
|
||||
))
|
||||
@crop2 = assign(:crop, stub_model(Crop,
|
||||
:id => 99,
|
||||
:system_name => "Maize"
|
||||
))
|
||||
assign(:recent_plantings, [ stub_model(Planting,
|
||||
@user = FactoryGirl.create(:user)
|
||||
@garden = FactoryGirl.create(:garden, :user => @user)
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@maize = FactoryGirl.create(:maize)
|
||||
assign(:recent_plantings, [
|
||||
FactoryGirl.create(:planting,
|
||||
:garden => @garden,
|
||||
:crop => @crop,
|
||||
:planted_at => '2008-01-05 12:34:56',
|
||||
:quantity => 3,
|
||||
:description => "MyText *ITALIC*",
|
||||
:created_at => Time.now
|
||||
:crop => @tomato
|
||||
),
|
||||
stub_model(Planting,
|
||||
FactoryGirl.create(:planting,
|
||||
:garden => @garden,
|
||||
:crop => @crop2,
|
||||
:crop => @maize,
|
||||
:description => '',
|
||||
:created_at => Time.now
|
||||
:planted_at => '2013-01-13 01:25:34'
|
||||
)
|
||||
])
|
||||
render
|
||||
@@ -42,11 +24,11 @@ describe "plantings/index" do
|
||||
it "renders a list of plantings" do
|
||||
rendered.should contain 'Tomato'
|
||||
rendered.should contain 'Maize'
|
||||
rendered.should contain "blah's My Awesome Allotment"
|
||||
rendered.should contain "user1's My Garden"
|
||||
end
|
||||
|
||||
it "shows descriptions where they exist" do
|
||||
rendered.should contain "MyText"
|
||||
rendered.should contain "This is a"
|
||||
end
|
||||
|
||||
it "shows filler when there is no description" do
|
||||
@@ -54,11 +36,11 @@ describe "plantings/index" do
|
||||
end
|
||||
|
||||
it "displays planting time" do
|
||||
rendered.should contain '2008-01-05 12:34:56'
|
||||
rendered.should contain '2013-01-13 01:25:34'
|
||||
end
|
||||
|
||||
it "renders markdown in the description" do
|
||||
assert_select "em", "ITALIC"
|
||||
assert_select "em", "really"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,12 +2,16 @@ require 'spec_helper'
|
||||
|
||||
describe "plantings/new" do
|
||||
before(:each) do
|
||||
assign(:planting, stub_model(Planting,
|
||||
:garden_id => 1,
|
||||
:crop_id => 1,
|
||||
:quantity => 1,
|
||||
:description => "MyText"
|
||||
).as_new_record)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
# create gardens and crops to populate dropdowns
|
||||
@garden1 = FactoryGirl.create(:garden, :user => @user, :name => 'Garden1')
|
||||
@garden2 = FactoryGirl.create(:garden, :user => @user, :name => 'Garden2')
|
||||
@crop1 = FactoryGirl.create(:tomato)
|
||||
@crop2 = FactoryGirl.create(:maize)
|
||||
|
||||
assign(:planting, FactoryGirl.create(:planting, :garden => @garden1))
|
||||
|
||||
end
|
||||
|
||||
context "logged out" do
|
||||
@@ -19,37 +23,9 @@ describe "plantings/new" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = User.create(:email => "growstuff@example.com",
|
||||
:password => "irrelevant")
|
||||
@user.confirm!
|
||||
sign_in @user
|
||||
|
||||
# create gardens and crops to populate dropdowns
|
||||
@garden1 = Garden.create!(
|
||||
:user_id => @user.id,
|
||||
:name => 'Garden1'
|
||||
)
|
||||
@garden2 = Garden.create!(
|
||||
:user_id => @user.id,
|
||||
:name => 'Garden2'
|
||||
)
|
||||
|
||||
@crop1 = Crop.create!(
|
||||
:system_name => 'Tomato',
|
||||
:en_wikipedia_url => 'http://blah'
|
||||
)
|
||||
@crop2 = Crop.create!(
|
||||
:system_name => 'Corn',
|
||||
:en_wikipedia_url => 'http://blah'
|
||||
)
|
||||
@crop3 = Crop.create!(
|
||||
:system_name => 'Chard',
|
||||
:en_wikipedia_url => 'http://blah'
|
||||
)
|
||||
|
||||
assign(:crop, @crop2)
|
||||
assign(:garden, @garden2)
|
||||
|
||||
render
|
||||
end
|
||||
|
||||
|
||||
@@ -2,39 +2,24 @@ require 'spec_helper'
|
||||
|
||||
describe "plantings/show" do
|
||||
before(:each) do
|
||||
@user = assign(:user, stub_model(User,
|
||||
:id => 23,
|
||||
:username => 'blah',
|
||||
:password => 'blahblah',
|
||||
:tos_agreement => true
|
||||
))
|
||||
@garden = assign(:garden, stub_model(Garden,
|
||||
:id => 42,
|
||||
:user => @user,
|
||||
:name => "My Awesome Allotment"
|
||||
))
|
||||
@crop = assign(:crop, stub_model(Crop,
|
||||
:id => 99,
|
||||
:system_name => "Tomato"
|
||||
))
|
||||
@planting = assign(:planting, stub_model(Planting,
|
||||
:garden => @garden,
|
||||
:crop => @crop,
|
||||
:quantity => 333,
|
||||
:description => "MyText *ITALIC*"
|
||||
))
|
||||
@user = FactoryGirl.create(:user)
|
||||
@garden = FactoryGirl.create(:garden, :user => @user)
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
@planting = assign(:planting,
|
||||
FactoryGirl.create(:planting, :garden => @garden, :crop => @crop)
|
||||
)
|
||||
render
|
||||
end
|
||||
|
||||
it "renders the quantity planted" do
|
||||
rendered.should match(/333/)
|
||||
rendered.should match(/3/)
|
||||
end
|
||||
|
||||
it "renders the description" do
|
||||
rendered.should match(/MyText/)
|
||||
rendered.should match(/This is a/)
|
||||
end
|
||||
|
||||
it "renders markdown in the description" do
|
||||
assert_select "em", "ITALIC"
|
||||
assert_select "em", "really"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ describe "scientific_names/edit" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:confirmed_user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ describe "scientific_names/new" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:confirmed_user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
@@ -2,12 +2,8 @@ require 'spec_helper'
|
||||
|
||||
describe "updates/edit" do
|
||||
before(:each) do
|
||||
@update = assign(:update, stub_model(Update,
|
||||
:user_id => 1,
|
||||
:subject => "MyString",
|
||||
:body => "MyText",
|
||||
:created_at => Time.now
|
||||
))
|
||||
@user = FactoryGirl.create(:user)
|
||||
@update = assign(:update, FactoryGirl.create(:update, :user => @user))
|
||||
end
|
||||
|
||||
context "logged out" do
|
||||
@@ -19,16 +15,11 @@ describe "updates/edit" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = User.create(:email => "growstuff@example.com",
|
||||
:password => "irrelevant")
|
||||
@user.confirm!
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
it "renders the edit update form" do
|
||||
render
|
||||
|
||||
assert_select "form", :action => updates_path(@update), :method => "post" do
|
||||
assert_select "input#update_subject", :name => "update[subject]"
|
||||
assert_select "textarea#update_body", :name => "update[body]"
|
||||
|
||||
@@ -2,34 +2,18 @@ require 'spec_helper'
|
||||
|
||||
describe "updates/index" do
|
||||
before(:each) do
|
||||
user = User.create!(
|
||||
:username => "test_user",
|
||||
:email => "test@growstuff.org",
|
||||
:password => "password",
|
||||
:tos_agreement => true
|
||||
)
|
||||
assign(:updates, [
|
||||
stub_model(Update,
|
||||
:user_id => user.id,
|
||||
:subject => "Subject",
|
||||
:body => "MyText",
|
||||
:created_at => Time.now
|
||||
),
|
||||
stub_model(Update,
|
||||
:user_id => user.id,
|
||||
:subject => "Subject",
|
||||
:body => "MyText",
|
||||
:created_at => Time.now
|
||||
)
|
||||
])
|
||||
@member = FactoryGirl.create(:user)
|
||||
@update1 = FactoryGirl.build(:update, :user => @member)
|
||||
@update2 = FactoryGirl.build(:update, :user => @member)
|
||||
assign(:updates, [@update1, @update2])
|
||||
render
|
||||
end
|
||||
|
||||
it "renders a list of updates" do
|
||||
assert_select "div.update", :count => 2
|
||||
assert_select "h3", :text => "Subject".to_s, :count => 2
|
||||
assert_select "h3", :text => "An Update".to_s, :count => 2
|
||||
assert_select "div.update-body",
|
||||
:text => "MyText".to_s, :count => 2
|
||||
:text => "This is some text.".to_s, :count => 2
|
||||
end
|
||||
|
||||
it "counts the number of updates" do
|
||||
|
||||
@@ -2,11 +2,8 @@ require 'spec_helper'
|
||||
|
||||
describe "updates/new" do
|
||||
before(:each) do
|
||||
assign(:update, stub_model(Update,
|
||||
:user_id => 1,
|
||||
:subject => "MyString",
|
||||
:body => "MyText"
|
||||
).as_new_record)
|
||||
@user = FactoryGirl.create(:user)
|
||||
assign(:update, FactoryGirl.create(:update, :user => @user))
|
||||
end
|
||||
|
||||
context "logged out" do
|
||||
@@ -18,9 +15,6 @@ describe "updates/new" do
|
||||
|
||||
context "logged in" do
|
||||
before(:each) do
|
||||
@user = User.create(:email => "growstuff@example.com",
|
||||
:password => "irrelevant")
|
||||
@user.confirm!
|
||||
sign_in @user
|
||||
render
|
||||
end
|
||||
|
||||
@@ -2,55 +2,35 @@ require 'spec_helper'
|
||||
|
||||
describe "updates/show" do
|
||||
before(:each) do
|
||||
@user = User.create!(
|
||||
:username => "test_user",
|
||||
:email => "test@example.com",
|
||||
:password => "password",
|
||||
:tos_agreement => true
|
||||
)
|
||||
@user = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
it "renders the post" do
|
||||
@update = assign(:update, stub_model(Update,
|
||||
:user_id => @user.id,
|
||||
:subject => "Subject",
|
||||
:body => "MyText"
|
||||
))
|
||||
@update = assign(:update,
|
||||
FactoryGirl.create(:update, :user => @user))
|
||||
render
|
||||
rendered.should match(/test_user/)
|
||||
# show the name of the member who posted the update
|
||||
rendered.should match(/user1/)
|
||||
# Subject goes in title
|
||||
rendered.should match(/MyText/)
|
||||
rendered.should match(/This is some text./)
|
||||
# shouldn't show the subject on a single post page
|
||||
# (it appears in the title/h1 via the layout, not via this view)
|
||||
rendered.should_not match(/An Update/)
|
||||
end
|
||||
|
||||
it "should parse markdown into html" do
|
||||
@update = assign(:update, stub_model(Update,
|
||||
:user_id => @user.id,
|
||||
:subject => "Subject",
|
||||
:body => "**strong**"
|
||||
))
|
||||
@update = assign(:update,
|
||||
FactoryGirl.create(:markdown_update, :user => @user))
|
||||
render
|
||||
rendered.should match(/<strong>strong<\/strong>/)
|
||||
assert_select "strong", "strong"
|
||||
end
|
||||
|
||||
it "shouldn't let html through in body" do
|
||||
@update = assign(:update, stub_model(Update,
|
||||
:user_id => @user.id,
|
||||
:subject => "<b>Subject<b>",
|
||||
:body => '<a href="http://evil.com">EVIL</a>'
|
||||
))
|
||||
@update = assign(:update,
|
||||
FactoryGirl.create(:html_update, :user => @user))
|
||||
render
|
||||
rendered.should match(/EVIL/)
|
||||
rendered.should_not match(/a href="http:\/\/evil.com"/)
|
||||
end
|
||||
|
||||
it "shouldn't show the subject on the single update page" do
|
||||
@update = assign(:update, stub_model(Update,
|
||||
:user_id => @user.id,
|
||||
:subject => "<b>Subject<b>",
|
||||
:body => '<a href="http://evil.com">EVIL</a>'
|
||||
))
|
||||
render
|
||||
rendered.should_not match(/Subject/)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user