mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-30 04:35:28 -04:00
Merge branch 'dev' into bootstrap3
This commit is contained in:
@@ -41,3 +41,4 @@ submit the change with your pull request.
|
||||
- Mackenzie "Maco" King / [maco](https://github.com/maco)
|
||||
- Amelia Greenhall / [ameliagreenhall](https://github.com/ameliagreenhall)
|
||||
- Barb Natali / [barbnatali](https://github.com/barbnatali)
|
||||
- Taylor Griffin / [tygriffin](https://github.com/tygriffin)
|
||||
|
||||
@@ -129,7 +129,7 @@ p.stats {
|
||||
display:block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.member-thumbnail {
|
||||
img {
|
||||
@@ -148,11 +148,11 @@ li.crop-hierarchy {
|
||||
}
|
||||
|
||||
.navbar-bottom {
|
||||
margin: 40px 0px 0px 0px !important;
|
||||
margin: 40px 0px 0px 0px !important;
|
||||
}
|
||||
|
||||
// navbar centering
|
||||
.navbar-nav {
|
||||
footer .navbar .nav {
|
||||
float: none;
|
||||
display: inline-block;
|
||||
*display: inline;
|
||||
|
||||
@@ -7,7 +7,14 @@ class CropsController < ApplicationController
|
||||
# GET /crops
|
||||
# GET /crops.json
|
||||
def index
|
||||
@crops = Crop.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
@sort = params[:sort]
|
||||
if @sort == 'alpha'
|
||||
# alphabetical order
|
||||
@crops = Crop.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
else
|
||||
# default to sorting by popularity
|
||||
@crops = Crop.popular.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
@@ -74,7 +81,9 @@ class CropsController < ApplicationController
|
||||
# GET /crops/new.json
|
||||
def new
|
||||
@crop = Crop.new
|
||||
|
||||
3.times do
|
||||
@crop.scientific_names.build
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html # new.html.haml
|
||||
format.json { render json: @crop }
|
||||
@@ -92,6 +101,7 @@ class CropsController < ApplicationController
|
||||
params[:crop][:creator_id] = current_member.id
|
||||
@crop = Crop.new(params[:crop])
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
if @crop.save
|
||||
format.html { redirect_to @crop, notice: 'Crop was successfully created.' }
|
||||
|
||||
7
app/controllers/passwords_controller.rb
Normal file
7
app/controllers/passwords_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class PasswordsController < Devise::PasswordsController
|
||||
|
||||
protected
|
||||
def after_resetting_password_path_for(resource)
|
||||
root_path
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,13 @@
|
||||
class Crop < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
attr_accessible :en_wikipedia_url, :name, :parent_id, :creator_id
|
||||
attr_accessible :en_wikipedia_url, :name, :parent_id, :creator_id, :scientific_names_attributes
|
||||
|
||||
has_many :scientific_names
|
||||
accepts_nested_attributes_for :scientific_names,
|
||||
:allow_destroy => true,
|
||||
:reject_if => :all_blank
|
||||
|
||||
has_many :plantings
|
||||
has_many :photos, :through => :plantings
|
||||
has_many :seeds
|
||||
@@ -17,6 +21,7 @@ class Crop < ActiveRecord::Base
|
||||
default_scope order("lower(name) asc")
|
||||
scope :recent, reorder("created_at desc")
|
||||
scope :toplevel, where(:parent_id => nil)
|
||||
scope :popular, reorder("plantings_count desc, lower(name) asc")
|
||||
scope :randomized, reorder('random()') # ok on sqlite and psql, but not on mysql
|
||||
|
||||
validates :en_wikipedia_url,
|
||||
|
||||
@@ -27,5 +27,17 @@
|
||||
.controls
|
||||
= collection_select(:crop, :parent_id, Crop.all, :id, :name, {:include_blank => true})
|
||||
%span.help-inline Optional. For setting up crop hierarchies for varieties etc.
|
||||
%p
|
||||
%span.help-block
|
||||
You may enter up to 3 scientific names for a crop. Most crops will have only one.
|
||||
= f.fields_for :scientific_names do |sn|
|
||||
.control-group
|
||||
= sn.label :scientific_name, "Scientific name", :class => 'control-label'
|
||||
.controls
|
||||
= sn.text_field :scientific_name
|
||||
- if sn.object && sn.object.persisted?
|
||||
%label.checkbox
|
||||
= sn.check_box :_destroy
|
||||
= sn.label :_destroy, "Delete"
|
||||
.form-actions
|
||||
= f.submit 'Save', :class => 'btn btn-primary'
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
View any crop page to see which of our members have planted it and find
|
||||
information on how to grow it yourself.
|
||||
|
||||
= form_tag(crops_path, :method => :get, :class => 'form-inline') do
|
||||
= label_tag :sort, "Sort by:", :class => 'control-label'
|
||||
= select_tag "sort", options_for_select({"Popularity" => 'popular', "Alphabetical" => 'alpha'}, @sort || 'popular')
|
||||
= submit_tag "Show", :class => 'btn btn-primary'
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @crops, :model => "crops"
|
||||
= will_paginate @crops
|
||||
|
||||
@@ -3,7 +3,7 @@ Growstuff::Application.routes.draw do
|
||||
resources :plant_parts
|
||||
|
||||
|
||||
devise_for :members, :controllers => { :registrations => "registrations" }
|
||||
devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" }
|
||||
resources :members
|
||||
|
||||
resources :photos
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class DefaultPlantingsCountToZero < ActiveRecord::Migration
|
||||
def up
|
||||
change_column :crops, :plantings_count, :integer, :default => 0
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :crops, :plantings_count, :integer, :default => nil
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131031000655) do
|
||||
ActiveRecord::Schema.define(:version => 20140718075753) do
|
||||
|
||||
create_table "account_types", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
@@ -51,13 +51,13 @@ ActiveRecord::Schema.define(:version => 20131031000655) do
|
||||
end
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.string "name", :null => false
|
||||
t.string "en_wikipedia_url"
|
||||
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.integer "parent_id"
|
||||
t.integer "plantings_count"
|
||||
t.integer "plantings_count", :default => 0
|
||||
t.integer "creator_id"
|
||||
end
|
||||
|
||||
@@ -242,11 +242,11 @@ ActiveRecord::Schema.define(:version => 20131031000655) do
|
||||
add_index "posts", ["slug"], :name => "index_updates_on_slug", :unique => true
|
||||
|
||||
create_table "products", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.text "description", :limit => 255, :null => false
|
||||
t.integer "min_price", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "name", :null => false
|
||||
t.text "description", :null => false
|
||||
t.integer "min_price", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "account_type_id"
|
||||
t.integer "paid_months"
|
||||
t.integer "recommended_price"
|
||||
|
||||
@@ -235,6 +235,17 @@ namespace :growstuff do
|
||||
PlantPart.find_or_create_by_name!(pp)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "July 2014: set planting_count to 0 by default, not nil"
|
||||
task :zero_plantings_count => :environment do
|
||||
Crop.find_each do |c|
|
||||
if c.plantings_count.nil?
|
||||
c.plantings_count = 0
|
||||
c.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end # end oneoff section
|
||||
|
||||
end
|
||||
|
||||
@@ -10,11 +10,5 @@
|
||||
# echo "YYYY-MM-DD - do something or other"
|
||||
# rake growstuff:oneoff:something
|
||||
|
||||
echo "2013-10-24 - fix zeroed geolocations"
|
||||
rake growstuff:depopulate_null_island
|
||||
|
||||
echo "2013-10-24 - initialize garden locations"
|
||||
rake growstuff:oneoff:initialize_garden_locations
|
||||
|
||||
echo "2013-10-31 - import plant parts"
|
||||
rake growstuff:oneoff:import_plant_parts
|
||||
echo "2013-07-18 - zero crop plantings_count"
|
||||
rake growstuff:oneoff:zero_plantings_count
|
||||
|
||||
@@ -52,6 +52,23 @@ describe Crop do
|
||||
end
|
||||
end
|
||||
|
||||
context 'popularity' do
|
||||
before (:each) do
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@maize = FactoryGirl.create(:maize)
|
||||
@cucumber = FactoryGirl.create(:crop, :name => 'cucumber')
|
||||
FactoryGirl.create_list(:planting, 10, :crop => @maize)
|
||||
FactoryGirl.create_list(:planting, 3, :crop => @tomato)
|
||||
end
|
||||
|
||||
it "sorts by most plantings" do
|
||||
Crop.popular.first.should eq @maize
|
||||
FactoryGirl.create_list(:planting, 10, :crop => @tomato)
|
||||
Crop.popular.first.should eq @tomato
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'finds a default scientific name' do
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
@crop.default_scientific_name.should eq nil
|
||||
|
||||
@@ -5,6 +5,7 @@ describe "crops/_popover" do
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@sn = FactoryGirl.create(:solanum_lycopersicum, :crop => @tomato)
|
||||
@planting = FactoryGirl.create(:planting, :crop => @tomato)
|
||||
@tomato.reload # to pick up latest plantings_count
|
||||
render :partial => 'crops/popover', :locals => { :crop => @tomato }
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@ describe "crops/edit" do
|
||||
controller.stub(:current_user) {
|
||||
FactoryGirl.create(:crop_wrangling_member)
|
||||
}
|
||||
@crop = assign(:crop, FactoryGirl.create(:maize))
|
||||
@crop = FactoryGirl.create(:maize)
|
||||
3.times do
|
||||
@crop.scientific_names.build
|
||||
end
|
||||
assign(:crop, @crop)
|
||||
render
|
||||
end
|
||||
|
||||
@@ -19,4 +23,10 @@ describe "crops/edit" do
|
||||
assert_select "input#crop_en_wikipedia_url", :name => "crop[en_wikipedia_url]"
|
||||
end
|
||||
end
|
||||
|
||||
it "shows three fields for scientific_name" do
|
||||
assert_select "input#crop_scientific_names_attributes_0_scientific_name", :count => 1
|
||||
assert_select "input#crop_scientific_names_attributes_1_scientific_name", :count => 1
|
||||
assert_select "input#crop_scientific_names_attributes_2_scientific_name", :count => 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,14 @@ describe "crops/index" do
|
||||
assign(:crops, crops)
|
||||
end
|
||||
|
||||
it "has a form for sorting by" do
|
||||
render
|
||||
assert_select "form"
|
||||
assert_select "select#sort"
|
||||
assert_select "option[value=alpha]"
|
||||
assert_select "option[value=popular]"
|
||||
end
|
||||
|
||||
it "renders a list of crops" do
|
||||
render
|
||||
assert_select "a", :text => @maize.name
|
||||
|
||||
@@ -2,7 +2,11 @@ require 'spec_helper'
|
||||
|
||||
describe "crops/new" do
|
||||
before(:each) do
|
||||
assign(:crop, FactoryGirl.create(:maize))
|
||||
@crop = FactoryGirl.create(:maize)
|
||||
3.times do
|
||||
@crop.scientific_names.build
|
||||
end
|
||||
assign(:crop, @crop)
|
||||
@member = FactoryGirl.create(:crop_wrangling_member)
|
||||
sign_in @member
|
||||
controller.stub(:current_user) { @member }
|
||||
@@ -22,4 +26,10 @@ describe "crops/new" do
|
||||
assert_select "a[href^=http://wiki.growstuff.org]", "crop wrangling guide"
|
||||
end
|
||||
|
||||
it "shows three fields for scientific_name" do
|
||||
assert_select "input#crop_scientific_names_attributes_0_scientific_name", :count => 1
|
||||
assert_select "input#crop_scientific_names_attributes_1_scientific_name", :count => 1
|
||||
assert_select "input#crop_scientific_names_attributes_2_scientific_name", :count => 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ describe "crops/show" do
|
||||
render
|
||||
end
|
||||
|
||||
it 'shows 4 photos across the top of the page' do
|
||||
it 'shows 3 photos across the top of the page' do
|
||||
assert_select "div.thumbnail>a>img", :count => 3
|
||||
end
|
||||
|
||||
@@ -131,12 +131,13 @@ describe "crops/show" do
|
||||
:garden => @garden,
|
||||
:crop => @crop
|
||||
)
|
||||
@crop.reload # to pick up latest plantings_count
|
||||
end
|
||||
|
||||
it "links to people who are growing this crop" do
|
||||
render
|
||||
rendered.should contain /member\d+/
|
||||
rendered.should contain "Springfield Community Garden"
|
||||
rendered.should contain @owner.login_name
|
||||
rendered.should contain @garden.name
|
||||
end
|
||||
|
||||
it "shows photos where available" do
|
||||
|
||||
Reference in New Issue
Block a user