Merge branch 'dev' into staff

This commit is contained in:
Skud
2013-07-09 10:05:37 +10:00
14 changed files with 141 additions and 53 deletions

View File

@@ -28,9 +28,16 @@ class PhotosController < ApplicationController
@photo = Photo.new
@planting_id = params[:planting_id]
page = params[:page] || 1
@flickr_auth = current_member.auth('flickr')
if @flickr_auth
@photos = current_member.flickr_photos
photos = current_member.flickr_photos(page)
total = photos.instance_of?(FlickRaw::ResponseList) ? photos.total : 0
@photos = WillPaginate::Collection.create(page, 30, total) do |pager|
pager.replace photos.to_a
end
end
respond_to do |format|

View File

@@ -148,8 +148,12 @@ class Member < ActiveRecord::Base
return @flickr
end
def flickr_photos
return flickr.people.getPhotos(:user_id => 'me', :per_page => 30)
def flickr_photos(page_num=1)
return flickr.people.getPhotos(
:user_id => 'me',
:page => page_num,
:per_page => 30
)
end
protected

View File

@@ -3,7 +3,7 @@ class Planting < ActiveRecord::Base
friendly_id :planting_slug, use: :slugged
attr_accessible :crop_id, :description, :garden_id, :planted_at,
:quantity, :sunniness
:quantity, :sunniness, :planted_from
belongs_to :garden
belongs_to :crop
@@ -29,6 +29,22 @@ class Planting < ActiveRecord::Base
:allow_nil => true,
:allow_blank => true
PLANTED_FROM_VALUES = [
'seed',
'seedling',
'cutting',
'root division',
'runner',
'bare root plant',
'advanced plant',
'graft',
'layering'
]
validates :planted_from, :inclusion => { :in => PLANTED_FROM_VALUES,
:message => "%{value} is not a valid planting method" },
:allow_nil => true,
:allow_blank => true
def planting_slug
"#{owner.login_name}-#{garden}-#{crop}".downcase.gsub(' ', '-')
end

View File

@@ -5,8 +5,12 @@
Connected to Flickr as
= succeed "." do
= link_to @flickr_auth.name, "http://flickr.com/photos/#{@flickr_auth.uid}"
Please select a photo from your recent uploads.
%p Select a photo from your recent uploads:
%div.pagination
= page_entries_info @photos, :model => "photos"
= will_paginate @photos
- c = 0
%ul.thumbnails

View File

@@ -20,6 +20,10 @@
= f.label 'How many?', :class => 'control-label'
.controls
= f.number_field :quantity, :class => 'input-small'
.control-group
= f.label 'Planted from:', :class => 'control-label'
.controls
= f.select(:planted_from, Planting::PLANTED_FROM_VALUES, {:include_blank => true})
.control-group
= f.label 'Sun or shade?', :class => 'control-label'
.controls

View File

@@ -13,7 +13,12 @@
= "(#{@planting.owner.location})"
%p
%b Quantity:
= @planting.quantity != 0 ? @planting.quantity : "not specified"
= @planting.quantity.blank? ? "not specified" : @planting.quantity
- if ! @planting.planted_from.blank?
%p
%b Planted from:
= @planting.planted_from
- if ! @planting.sunniness.blank?
%p

View File

@@ -0,0 +1,5 @@
class AddPlantedFromToPlanting < ActiveRecord::Migration
def change
add_column :plantings, :planted_from, :string
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130606233733) do
ActiveRecord::Schema.define(:version => 20130705104238) do
create_table "account_types", :force => true do |t|
t.string "name", :null => false
@@ -179,15 +179,16 @@ ActiveRecord::Schema.define(:version => 20130606233733) do
end
create_table "plantings", :force => true do |t|
t.integer "garden_id", :null => false
t.integer "crop_id", :null => false
t.integer "garden_id", :null => false
t.integer "crop_id", :null => false
t.date "planted_at"
t.integer "quantity"
t.text "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "slug"
t.string "sunniness"
t.string "planted_from"
end
add_index "plantings", ["slug"], :name => "index_plantings_on_slug", :unique => true

View File

@@ -6,5 +6,6 @@ FactoryGirl.define do
quantity 33
description "This is a *really* good plant."
sunniness 'sun'
planted_from 'seed'
end
end

View File

@@ -49,21 +49,44 @@ describe Planting do
end
end
it 'should have a sunniness value' do
@planting.sunniness.should eq 'sun'
end
context 'sunniness' do
it 'should have a sunniness value' do
@planting.sunniness.should eq 'sun'
end
it 'all three valid sunniness values should work' do
['sun', 'shade', 'semi-shade', nil, ''].each do |s|
@planting = FactoryGirl.build(:planting, :sunniness => s)
@planting.should be_valid
it 'all three valid sunniness values should work' do
['sun', 'shade', 'semi-shade', nil, ''].each do |s|
@planting = FactoryGirl.build(:planting, :sunniness => s)
@planting.should be_valid
end
end
it 'should refuse invalid sunniness values' do
@planting = FactoryGirl.build(:planting, :sunniness => 'not valid')
@planting.should_not be_valid
@planting.errors[:sunniness].should include("not valid is not a valid sunniness value")
end
end
it 'should refuse invalid sunniness values' do
@planting = FactoryGirl.build(:planting, :sunniness => 'not valid')
@planting.should_not be_valid
@planting.errors[:sunniness].should include("not valid is not a valid sunniness value")
context 'planted from' do
it 'should have a planted_from value' do
@planting.planted_from.should eq 'seed'
end
it 'all valid planted_from values should work' do
['seed', 'seedling', 'cutting', 'root division',
'runner', 'bare root plant', 'advanced plant',
'graft', 'layering', nil, ''].each do |p|
@planting = FactoryGirl.build(:planting, :planted_from => p)
@planting.should be_valid
end
end
it 'should refuse invalid planted_from values' do
@planting = FactoryGirl.build(:planting, :planted_from => 'not valid')
@planting.should_not be_valid
@planting.errors[:planted_from].should include("not valid is not a valid planting method")
end
end
# we decided that all the tests for the planting/photo association would

View File

@@ -4,7 +4,13 @@ describe "photos/new" do
before(:each) do
@member = FactoryGirl.create(:member)
controller.stub(:current_user) { @member }
assign(:photos, [])
page = 1
per_page = 2
total_entries = 2
photos = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
pager.replace([])
end
assign(:photos, photos)
assign(:flickr_auth, FactoryGirl.create(:flickr_authentication, :member => @member))
end

View File

@@ -33,6 +33,8 @@ describe "plantings/edit" do
assert_select "form", :action => plantings_path(@planting), :method => "post" do
assert_select "input#planting_quantity", :name => "planting[quantity]"
assert_select "textarea#planting_description", :name => "planting[description]"
assert_select "select#planting_sunniness", :name => "planting[sunniness]"
assert_select "select#planting_planted_from", :name => "planting[planted_from]"
end
end

View File

@@ -34,6 +34,7 @@ describe "plantings/new" do
assert_select "input#planting_quantity", :name => "planting[quantity]"
assert_select "textarea#planting_description", :name => "planting[description]"
assert_select "select#planting_sunniness", :name => "planting[sunniness]"
assert_select "select#planting_planted_from", :name => "planting[planted_from]"
end
end

View File

@@ -9,30 +9,46 @@ describe "plantings/show" do
)
end
it "shows the sunniness" do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:member)
create_planting_for(@member)
render
rendered.should contain 'Sun or shade?'
rendered.should contain 'sun'
end
it "doesn't show sunniness if blank" do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:member)
@p = create_planting_for(@member)
@p.sunniness = ''
@p.save
render
rendered.should_not contain 'Sun or shade?'
rendered.should_not contain 'sun'
end
it "shows photos" do
before (:each) do
@member = FactoryGirl.create(:member)
controller.stub(:current_user) { @member }
@p = create_planting_for(@member)
end
context 'sunniness' do
it "shows the sunniness" do
render
rendered.should contain 'Sun or shade?'
rendered.should contain 'sun'
end
it "doesn't show sunniness if blank" do
@p.sunniness = ''
@p.save
render
rendered.should_not contain 'Sun or shade?'
rendered.should_not contain 'sun'
end
end
context 'planted from' do
it "shows planted_from" do
render
rendered.should contain 'Planted from:'
rendered.should contain 'seed'
end
it "doesn't show planted_from if blank" do
@p.planted_from = ''
@p.save
render
rendered.should_not contain 'Planted from:'
rendered.should_not contain 'seed'
end
end
it "shows photos" do
@photo = FactoryGirl.create(:photo, :owner => @member)
@p.photos << @photo
render
@@ -40,18 +56,12 @@ describe "plantings/show" do
end
it "shows a link to add photos" do
@member = FactoryGirl.create(:member)
controller.stub(:current_user) { @member }
@p = create_planting_for(@member)
render
rendered.should contain "Add photo"
end
context "no location set" do
before(:each) do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:member)
create_planting_for(@member)
render
end
@@ -74,9 +84,8 @@ describe "plantings/show" do
context "location set" do
before(:each) do
controller.stub(:current_user) { nil }
@member = FactoryGirl.create(:london_member)
create_planting_for(@member)
@member.location = 'Greenwich, UK'
@member.save
render
end