whitespace fixes and um oops no there shouldn't be a secret key in that config file

This commit is contained in:
Mackenzie Morgan committed 2014-09-09 20:31:14 -04:00
1 parent 2b7b5bad63
commit ed537e583b
4 files changed
+41 -42

No files matched your search

+24 -24
View File
@@ -64,32 +64,32 @@ class PhotosController < ApplicationController
@photo.owner_id = current_member.id
@photo.set_flickr_metadata
# several models can have photos. we need to know what model and the id
# for the entry to attach the photo to
valid_models = ["planting", "harvest"]
# several models can have photos. we need to know what model and the id
# for the entry to attach the photo to
valid_models = ["planting", "harvest"]
if params[:type]
if valid_models.include?(params[:type])
if params[:id]
item = params[:type].camelcase.constantize.find_by_id(params[:id])
if item
if item.owner.id == current_member.id
# This syntax is weird, so just know that it means this:
# @photo.harvests << item unless @photo.harvests.include?(item)
# but with the correct many-to-many relationship automatically referenced
(@photo.send "#{params[:type]}s") << item unless (@photo.send "#{params[:type]}s").include?(item)
else
flash[:alert] = "You must own both the #{params[:type]} and the photo."
end
else
flash[:alert] = "Couldn't find #{params[:type]} to connect to photo."
end
else
flash[:alert] = "Missing id parameter"
end
else
flash[:alert] = "Cannot attach photos to #{params[:type]}"
end
else
if params[:id]
item = params[:type].camelcase.constantize.find_by_id(params[:id])
if item
if item.owner.id == current_member.id
# This syntax is weird, so just know that it means this:
# @photo.harvests << item unless @photo.harvests.include?(item)
# but with the correct many-to-many relationship automatically referenced
(@photo.send "#{params[:type]}s") << item unless (@photo.send "#{params[:type]}s").include?(item)
else
flash[:alert] = "You must own both the #{params[:type]} and the photo."
end
else
flash[:alert] = "Couldn't find #{params[:type]} to connect to photo."
end
else
flash[:alert] = "Missing id parameter"
end
else
flash[:alert] = "Cannot attach photos to #{params[:type]}"
end
else
flash[:alert] = "Missing type parameter"
end
+2 -2
View File
@@ -6,8 +6,8 @@ class Photo < ActiveRecord::Base
has_and_belongs_to_many :plantings
has_and_belongs_to_many :harvests
before_destroy do |photo|
photo.plantings.clear
photo.harvests.clear
photo.plantings.clear
photo.harvests.clear
end
default_scope order("created_at desc")
+1 -2
View File
@@ -6,8 +6,7 @@ Devise.setup do |config|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "Growstuff <noreply@growstuff.org>"
#config.secret_key = ENV['RAILS_SECRET_TOKEN']
config.secret_key = '6ccb49df7c02ce710c37ec3eadd81ec65e732708bd859ce6076f42593f0cff186b7c35be2fd195f46c9e923296ee07bf309eb33866fe1ea7d9ffeb88f367489c'
config.secret_key = ENV['RAILS_SECRET_TOKEN']
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
+14 -14
View File
@@ -39,13 +39,13 @@ describe PhotosController do
it "assigns a planting id" do
get :new, { :type => "planting", :id => 5 }
assigns(:id).should eq "5"
assigns(:type).should eq "planting"
assigns(:type).should eq "planting"
end
it "assigns a harvest id" do
get :new, { :type => "harvest", :id => 5 }
assigns(:id).should eq "5"
assigns(:type).should eq "harvest"
assigns(:type).should eq "harvest"
end
it "assigns the current set as @current_set" do
@@ -76,7 +76,7 @@ describe PhotosController do
planting = FactoryGirl.create(:planting, :garden => garden, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "planting",
:type => "planting",
:id => planting.id }
Photo.last.plantings.first.should eq planting
end
@@ -88,10 +88,10 @@ describe PhotosController do
planting = FactoryGirl.create(:planting, :garden => garden, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "planting",
:type => "planting",
:id => planting.id }
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "planting",
:type => "planting",
:id => planting.id }
Photo.last.plantings.count.should eq 1
end
@@ -102,7 +102,7 @@ describe PhotosController do
harvest = FactoryGirl.create(:harvest, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "harvest",
:type => "harvest",
:id => harvest.id }
Photo.last.harvests.first.should eq harvest
end
@@ -113,14 +113,14 @@ describe PhotosController do
harvest = FactoryGirl.create(:harvest, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "harvest",
:type => "harvest",
:id => harvest.id }
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "harvest",
:type => "harvest",
:id => harvest.id }
Photo.last.harvests.count.should eq 1
end
end
end
end
describe "for the second time" do
it "does not add a photo twice" do
@@ -141,7 +141,7 @@ describe PhotosController do
planting = FactoryGirl.create(:planting, :garden => garden, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "planting",
:type => "planting",
:id => planting.id }
Photo.last.plantings.first.should eq planting
end
@@ -152,7 +152,7 @@ describe PhotosController do
harvest = FactoryGirl.create(:harvest, :owner => member)
photo = FactoryGirl.create(:photo, :owner => member)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "harvest",
:type => "harvest",
:id => harvest.id }
Photo.last.harvests.first.should eq harvest
end
@@ -164,7 +164,7 @@ describe PhotosController do
planting = FactoryGirl.create(:planting)
photo = FactoryGirl.create(:photo)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "planting",
:type => "planting",
:id => planting.id }
Photo.last.plantings.first.should_not eq planting
end
@@ -174,7 +174,7 @@ describe PhotosController do
harvest = FactoryGirl.create(:harvest)
photo = FactoryGirl.create(:photo)
post :create, {:photo => { :flickr_photo_id => photo.flickr_photo_id },
:type => "harvest",
:type => "harvest",
:id => harvest.id }
Photo.last.harvests.first.should_not eq harvest
end