mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
Merge branch 'dev' into payments-new
This commit is contained in:
BIN
app/assets/images/placeholder_150.png
Normal file
BIN
app/assets/images/placeholder_150.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -5,6 +5,7 @@ class Crop < ActiveRecord::Base
|
||||
|
||||
has_many :scientific_names
|
||||
has_many :plantings
|
||||
has_many :photos, :through => :plantings
|
||||
|
||||
belongs_to :parent, :class_name => 'Crop'
|
||||
has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id'
|
||||
@@ -38,4 +39,8 @@ class Crop < ActiveRecord::Base
|
||||
return plantings.count
|
||||
end
|
||||
|
||||
def default_photo
|
||||
return photos.first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,9 @@ class Photo < ActiveRecord::Base
|
||||
attr_accessible :flickr_photo_id, :owner_id, :title, :license_name,
|
||||
:license_url, :thumbnail_url, :fullsize_url, :link_url
|
||||
belongs_to :owner, :class_name => 'Member'
|
||||
|
||||
has_and_belongs_to_many :plantings
|
||||
before_destroy {|photo| photo.plantings.clear}
|
||||
|
||||
default_scope order("created_at desc")
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ class Planting < ActiveRecord::Base
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :crop
|
||||
|
||||
has_and_belongs_to_many :photos
|
||||
before_destroy {|planting| planting.photos.clear}
|
||||
|
||||
default_scope order("created_at desc")
|
||||
|
||||
@@ -50,4 +52,8 @@ class Planting < ActiveRecord::Base
|
||||
def to_s
|
||||
self.crop_system_name + " in " + self.location
|
||||
end
|
||||
|
||||
def default_photo
|
||||
return photos.first
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
|
||||
%pubDate= comment.created_at.to_s(:rfc822)
|
||||
%link= post_url(comment.post)
|
||||
%guid= post_url(comment.post)
|
||||
%guid= comment_url(comment)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.thumbnail(style='height: 220px')
|
||||
- if crop
|
||||
= link_to image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded'), crop
|
||||
= link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => crop.system_name, :class => 'img-rounded'), crop
|
||||
%p
|
||||
= link_to crop.system_name, crop
|
||||
- if crop.scientific_names.count > 0
|
||||
@@ -12,6 +12,3 @@
|
||||
%small
|
||||
Planted
|
||||
= pluralize(crop.plantings_count, "time")
|
||||
- else
|
||||
= image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded')
|
||||
Sample crop
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
- content_for :title, "Photos"
|
||||
- content_for :title, "Photo Gallery"
|
||||
|
||||
%p This page shows all your photos.
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @photos, :model => "photos"
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
%p
|
||||
= link_to "View on Flickr", @photo.link_url
|
||||
|
||||
- if can? :destroy, @photo
|
||||
%p= link_to 'Delete Photo', @photo, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini'
|
||||
|
||||
.span6
|
||||
- if @photo.plantings.count > 0
|
||||
%p This photo depicts:
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
.well
|
||||
%h4
|
||||
- if defined?(title) && title == 'owner'
|
||||
= link_to planting.owner, planting.owner
|
||||
- else
|
||||
= link_to planting.crop.system_name, planting
|
||||
.row-fluid
|
||||
.span3
|
||||
= link_to image_tag((planting.default_photo ? planting.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => '', :class => 'img-rounded'), planting
|
||||
|
||||
.span9
|
||||
%h4
|
||||
- if defined?(title) && title == 'owner'
|
||||
= link_to planting.owner, planting.owner
|
||||
- else
|
||||
= link_to planting.crop.system_name, planting
|
||||
|
||||
%p
|
||||
Planted
|
||||
- if planting.planted_at
|
||||
= planting.planted_at
|
||||
in
|
||||
= link_to planting.location, planting.garden
|
||||
%p
|
||||
Planted
|
||||
- if planting.planted_at
|
||||
= planting.planted_at
|
||||
in
|
||||
= link_to planting.location, planting.garden
|
||||
|
||||
%p
|
||||
- if planting.quantity
|
||||
Quantity:
|
||||
= planting.quantity
|
||||
- else
|
||||
|
||||
%p
|
||||
- if planting.quantity
|
||||
Quantity:
|
||||
= planting.quantity
|
||||
- else
|
||||
|
||||
|
||||
- if planting.description && ! defined?(hide_description)
|
||||
%div
|
||||
:markdown
|
||||
#{ planting.description }
|
||||
- if planting.description && ! defined?(hide_description)
|
||||
%div
|
||||
:markdown
|
||||
#{ planting.description }
|
||||
|
||||
- if can? :edit, planting or can? :destroy, planting
|
||||
%p
|
||||
- if can? :edit, planting
|
||||
=link_to 'Edit', edit_planting_path(planting), :class => 'btn btn-mini'
|
||||
- if can? :destroy, planting
|
||||
=link_to 'Delete', planting, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini'
|
||||
- if can? :edit, planting or can? :destroy, planting
|
||||
%p
|
||||
- if can? :edit, planting
|
||||
=link_to 'Edit', edit_planting_path(planting), :class => 'btn btn-mini'
|
||||
- if can? :destroy, planting
|
||||
=link_to 'Delete', planting, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini'
|
||||
|
||||
@@ -30,24 +30,27 @@
|
||||
|
||||
.span6
|
||||
.well
|
||||
%h3
|
||||
= link_to @planting.crop, @planting.crop
|
||||
- if can? :edit, @planting
|
||||
= link_to 'Plant another', new_planting_path, :class => 'btn btn-primary'
|
||||
- elsif can? :create, Planting
|
||||
= link_to 'Plant this', new_planting_path, :class => 'btn btn-primary'
|
||||
.row-fluid
|
||||
.span4
|
||||
= link_to image_tag((@planting.crop.default_photo ? @planting.crop.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => '', :class => 'img-rounded'), @planting.crop
|
||||
.span8
|
||||
%h3
|
||||
= link_to @planting.crop, @planting.crop
|
||||
- if can? :edit, @planting
|
||||
= link_to 'Plant another', new_planting_path, :class => 'btn btn-primary'
|
||||
- elsif can? :create, Planting
|
||||
= link_to 'Plant this', new_planting_path, :class => 'btn btn-primary'
|
||||
|
||||
%p
|
||||
%b Scientific name:
|
||||
= @planting.crop_default_scientific_name
|
||||
%p
|
||||
%b
|
||||
Planted
|
||||
= pluralize(@planting.crop_plantings_count, "time")
|
||||
by #{Growstuff::Application.config.site_name} members
|
||||
%p
|
||||
%b Scientific name:
|
||||
= @planting.crop_default_scientific_name
|
||||
%p
|
||||
%b
|
||||
Planted
|
||||
= pluralize(@planting.crop_plantings_count, "time")
|
||||
by #{Growstuff::Application.config.site_name} members
|
||||
|
||||
%h2
|
||||
Notes
|
||||
%h2 Notes
|
||||
|
||||
:markdown
|
||||
#{ @planting.description != "" ? @planting.description : "No description given." }
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
|
||||
%pubDate= comment.created_at.to_s(:rfc822)
|
||||
%link= post_url(@post)
|
||||
%guid= post_url(@post)
|
||||
%guid= comment_url(comment)
|
||||
|
||||
@@ -69,4 +69,14 @@ describe Crop do
|
||||
@tomato.varieties.should eq [@roma]
|
||||
end
|
||||
end
|
||||
|
||||
context 'photos' do
|
||||
it 'has a default photo' do
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
@planting = FactoryGirl.create(:planting, :crop => @crop)
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
@planting.photos << @photo
|
||||
@crop.default_photo.should be_an_instance_of Photo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,13 +86,28 @@ describe Planting do
|
||||
@planting.errors[:sunniness].should include("not valid is not a valid sunniness value")
|
||||
end
|
||||
|
||||
# we decided that all the tests for the planting/photo association would
|
||||
# be done on this side, not on the photos side
|
||||
context 'photos' do
|
||||
it 'has a photo' do
|
||||
before(:each) do
|
||||
@planting = FactoryGirl.create(:planting)
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
@planting.photos << @photo
|
||||
end
|
||||
|
||||
it 'has a photo' do
|
||||
@planting.photos.first.should eq @photo
|
||||
end
|
||||
|
||||
it 'deletes association with photos when photo is deleted' do
|
||||
@photo.destroy
|
||||
@planting.reload
|
||||
@planting.photos.should be_empty
|
||||
end
|
||||
|
||||
it 'has a default photo' do
|
||||
@planting.default_photo.should eq @photo
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,11 +6,10 @@ describe "crops/index" do
|
||||
page = 1
|
||||
per_page = 2
|
||||
total_entries = 2
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@maize = FactoryGirl.create(:maize)
|
||||
crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
|
||||
pager.replace([
|
||||
FactoryGirl.create(:tomato),
|
||||
FactoryGirl.create(:maize)
|
||||
])
|
||||
pager.replace([ @tomato, @maize ])
|
||||
end
|
||||
assign(:crops, crops)
|
||||
end
|
||||
@@ -21,6 +20,14 @@ describe "crops/index" do
|
||||
assert_select "a", :text => "Tomato"
|
||||
end
|
||||
|
||||
it "shows photos where available" do
|
||||
@planting = FactoryGirl.create(:planting, :crop => @tomato)
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
@planting.photos << @photo
|
||||
render
|
||||
assert_select "img", :src => @photo.thumbnail_url
|
||||
end
|
||||
|
||||
it "linkifies crop images" do
|
||||
render
|
||||
assert_select "img", :src => :tomato
|
||||
|
||||
@@ -44,6 +44,14 @@ describe "crops/show" do
|
||||
rendered.should contain "Springfield Community Garden"
|
||||
end
|
||||
|
||||
it "shows photos where available" do
|
||||
@planting = FactoryGirl.create(:planting, :crop => @crop)
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
@planting.photos << @photo
|
||||
render
|
||||
assert_select "img", :src => @photo.thumbnail_url
|
||||
end
|
||||
|
||||
context 'varieties' do
|
||||
before(:each) do
|
||||
@popcorn = FactoryGirl.create(:popcorn, :parent_id => @crop.id)
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "photos/show" do
|
||||
before(:each) do
|
||||
@member = FactoryGirl.create(:member)
|
||||
controller.stub(:current_user) { @member }
|
||||
end
|
||||
|
||||
context "CC-licensed photo" do
|
||||
before(:each) do
|
||||
@photo = assign(:photo, FactoryGirl.create(:photo))
|
||||
@photo = assign(:photo, FactoryGirl.create(:photo, :owner => @member))
|
||||
render
|
||||
end
|
||||
|
||||
@@ -23,6 +28,10 @@ describe "photos/show" do
|
||||
it "shows a link to the original image" do
|
||||
assert_select "a", :href => @photo.link_url, :text => "View on Flickr"
|
||||
end
|
||||
|
||||
it "has a delete button" do
|
||||
assert_select "a[href=#{photo_path(@photo)}]", 'Delete Photo'
|
||||
end
|
||||
end
|
||||
|
||||
context "unlicensed photo" do
|
||||
@@ -34,6 +43,7 @@ describe "photos/show" do
|
||||
it "contains the phrase 'All rights reserved'" do
|
||||
rendered.should contain "All rights reserved"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "linked to a planting" do
|
||||
|
||||
Reference in New Issue
Block a user