mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-16 12:40:07 -04:00
Merge branch 'dev' into places2
Fix up broken indentation on navbar. Conflicts: app/views/layouts/_header.html.haml
This commit is contained in:
@@ -108,14 +108,9 @@ h3 {
|
||||
margin-left: 0px
|
||||
}
|
||||
|
||||
.three-across:nth-child(3):after {
|
||||
content: "\A";
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.three-across:nth-child(3n+1) {
|
||||
margin-left: 0px;
|
||||
clear: all;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
// let's condense the hero unit a little
|
||||
|
||||
@@ -3,6 +3,20 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
after_filter :store_location
|
||||
|
||||
def store_location
|
||||
# store last url - this is needed for post-login redirect to whatever the user last visited.
|
||||
if (request.fullpath != new_member_session_path && \
|
||||
!request.xhr?) # don't store ajax calls
|
||||
session[:previous_url] = request.fullpath
|
||||
end
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
session[:previous_url] || root_path
|
||||
end
|
||||
|
||||
# tweak CanCan defaults because we don't have a "current_user" method
|
||||
# this means that we use current_user in specs but current_member everywhere
|
||||
# else in the code.
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
class CommentsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
cache_sweeper :comment_sweeper
|
||||
|
||||
# GET /comments
|
||||
# GET /comments.json
|
||||
def index
|
||||
|
||||
@@ -6,7 +6,7 @@ class CropsController < ApplicationController
|
||||
# GET /crops
|
||||
# GET /crops.json
|
||||
def index
|
||||
@crops = Crop.paginate(:page => params[:page])
|
||||
@crops = Crop.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.haml
|
||||
@@ -15,10 +15,19 @@ class CropsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /wrangle
|
||||
def wrangle
|
||||
@crops = Crop.recent.paginate(:page => params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# GET /crops/1
|
||||
# GET /crops/1.json
|
||||
def show
|
||||
@crop = Crop.find(params[:id])
|
||||
@crop = Crop.includes(:scientific_names, {:plantings => :photos}).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
@@ -45,6 +54,7 @@ class CropsController < ApplicationController
|
||||
# POST /crops
|
||||
# POST /crops.json
|
||||
def create
|
||||
params[:crop][:creator_id] = current_member.id
|
||||
@crop = Crop.new(params[:crop])
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
@@ -6,10 +6,11 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings
|
||||
# GET /plantings.json
|
||||
def index
|
||||
@plantings = Planting.paginate(:page => params[:page])
|
||||
@owner = Member.find_by_slug(params[:owner])
|
||||
if @owner
|
||||
@plantings = @owner.plantings.paginate(:page => params[:page])
|
||||
@plantings = @owner.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page])
|
||||
else
|
||||
@plantings = Planting.includes(:owner, :crop, :garden).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@@ -22,7 +23,7 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings/1
|
||||
# GET /plantings/1.json
|
||||
def show
|
||||
@planting = Planting.find(params[:id])
|
||||
@planting = Planting.includes(:owner, :crop, :garden, :photos).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
|
||||
@@ -7,10 +7,11 @@ class PostsController < ApplicationController
|
||||
# GET /posts.json
|
||||
|
||||
def index
|
||||
@posts = Post.paginate(:page => params[:page])
|
||||
@author = Member.find_by_slug(params[:author])
|
||||
if @author
|
||||
@posts = @author.posts.paginate(:page => params[:page])
|
||||
@posts = @author.posts.includes(:author, { :comments => :author }).paginate(:page => params[:page])
|
||||
else
|
||||
@posts = Post.includes(:author, { :comments => :author }).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@@ -23,8 +24,7 @@ class PostsController < ApplicationController
|
||||
# GET /posts/1
|
||||
# GET /posts/1.json
|
||||
def show
|
||||
@post = Post.find(params[:id])
|
||||
@comments = @post.comments
|
||||
@post = Post.includes(:author, { :comments => :author }).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
|
||||
@@ -45,6 +45,7 @@ class ScientificNamesController < ApplicationController
|
||||
# POST /scientific_names
|
||||
# POST /scientific_names.json
|
||||
def create
|
||||
params[:scientific_name][:creator_id] = current_member.id
|
||||
@scientific_name = ScientificName.new(params[:scientific_name])
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
@@ -6,10 +6,11 @@ class SeedsController < ApplicationController
|
||||
# GET /seeds
|
||||
# GET /seeds.json
|
||||
def index
|
||||
@seeds = Seed.paginate(:page => params[:page])
|
||||
@owner = Member.find_by_slug(params[:owner])
|
||||
if @owner
|
||||
@seeds = @owner.seeds.paginate(:page => params[:page])
|
||||
@seeds = @owner.seeds.includes(:owner, :crop).paginate(:page => params[:page])
|
||||
else
|
||||
@seeds = Seed.includes(:owner, :crop).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
@@ -37,6 +37,7 @@ class Ability
|
||||
|
||||
# only crop wranglers can create/edit/destroy crops
|
||||
if member.has_role? :crop_wrangler
|
||||
can :wrangle, Crop
|
||||
can :manage, Crop
|
||||
can :manage, ScientificName
|
||||
end
|
||||
|
||||
15
app/models/comment_sweeper.rb
Normal file
15
app/models/comment_sweeper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class CommentSweeper < ActionController::Caching::Sweeper
|
||||
observe Comment
|
||||
|
||||
def after_create(comment)
|
||||
expire_fragment('recent_posts')
|
||||
end
|
||||
|
||||
def after_update(comment)
|
||||
end
|
||||
|
||||
def after_destroy(comment)
|
||||
expire_fragment('recent_posts')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,12 +1,13 @@
|
||||
class Crop < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :system_name, use: :slugged
|
||||
attr_accessible :en_wikipedia_url, :system_name, :parent_id
|
||||
attr_accessible :en_wikipedia_url, :system_name, :parent_id, :creator_id
|
||||
|
||||
has_many :scientific_names
|
||||
has_many :plantings
|
||||
has_many :photos, :through => :plantings
|
||||
has_many :seeds
|
||||
belongs_to :creator, :class_name => 'Member'
|
||||
|
||||
belongs_to :parent, :class_name => 'Crop'
|
||||
has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id'
|
||||
|
||||
@@ -3,10 +3,14 @@ class GardenSweeper < ActionController::Caching::Sweeper
|
||||
|
||||
def after_create(garden)
|
||||
expire_fragment('homepage_stats')
|
||||
expire_fragment('interesting_members') if garden.owner.interesting?
|
||||
expire_fragment("member_thumbnail_#{garden.owner.id}")
|
||||
end
|
||||
|
||||
def after_destroy(garden)
|
||||
expire_fragment('homepage_stats')
|
||||
expire_fragment('interesting_members') if garden.owner.interesting?
|
||||
expire_fragment("member_thumbnail_#{garden.owner.id}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class Member < ActiveRecord::Base
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :login_name, :email, :password, :password_confirmation,
|
||||
:remember_me, :login, :tos_agreement, :show_email,
|
||||
:location, :latitude, :longitude, :send_notification_email
|
||||
:location, :latitude, :longitude, :send_notification_email, :bio
|
||||
|
||||
# set up geocoding
|
||||
geocoded_by :location
|
||||
|
||||
@@ -4,6 +4,7 @@ class PlantingSweeper < ActionController::Caching::Sweeper
|
||||
def after_create(planting)
|
||||
expire_fragment('homepage_stats')
|
||||
expire_fragment("member_thumbnail_#{planting.owner.id}")
|
||||
expire_fragment("interesting_members") if planting.owner.interesting?
|
||||
expire_fragment("crop_image_#{planting.crop.id}")
|
||||
end
|
||||
|
||||
@@ -17,6 +18,7 @@ class PlantingSweeper < ActionController::Caching::Sweeper
|
||||
expire_fragment('homepage_stats')
|
||||
expire_fragment("crop_image_#{planting.crop.id}")
|
||||
expire_fragment('interesting_plantings') if planting.interesting?
|
||||
expire_fragment("interesting_members") if planting.owner.interesting?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -25,10 +25,14 @@ class Post < ActiveRecord::Base
|
||||
self.comments.count
|
||||
end
|
||||
|
||||
# return the timestamp of the most recent activity on this post
|
||||
# i.e. the time of the most recent comment, or of the post itself if
|
||||
# there are no comments.
|
||||
def recent_activity
|
||||
self.comments.reorder.last ? self.comments.reorder.last.created_at : self.created_at
|
||||
self.comments.present? ? self.comments.reorder('created_at DESC').first.created_at : self.created_at
|
||||
end
|
||||
|
||||
# return posts sorted by recent activity
|
||||
def Post.recently_active
|
||||
Post.all.sort do |a,b|
|
||||
b.recent_activity <=> a.recent_activity
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class ScientificName < ActiveRecord::Base
|
||||
attr_accessible :crop_id, :scientific_name
|
||||
attr_accessible :crop_id, :scientific_name, :creator_id
|
||||
belongs_to :crop
|
||||
belongs_to :creator, :class_name => 'Member'
|
||||
end
|
||||
|
||||
@@ -5,6 +5,8 @@ class SeedSweeper < ActionController::Caching::Sweeper
|
||||
if seed.tradable? && seed.interesting?
|
||||
expire_fragment('interesting_seeds')
|
||||
end
|
||||
expire_fragment('interesting_members') if seed.owner.interesting?
|
||||
expire_fragment("member_thumbnail_#{seed.owner.id}")
|
||||
end
|
||||
|
||||
def after_update(seed)
|
||||
@@ -15,6 +17,8 @@ class SeedSweeper < ActionController::Caching::Sweeper
|
||||
if seed.tradable? && seed.interesting?
|
||||
expire_fragment('interesting_seeds')
|
||||
end
|
||||
expire_fragment('interesting_members') if seed.owner.interesting?
|
||||
expire_fragment("member_thumbnail_#{seed.owner.id}")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
- content_for :title, "Editing crop"
|
||||
|
||||
%p
|
||||
Added by
|
||||
= @crop.creator
|
||||
= distance_of_time_in_words(@crop.created_at, Time.zone.now)
|
||||
ago.
|
||||
|
||||
= render 'form'
|
||||
|
||||
|
||||
38
app/views/crops/wrangle.html.haml
Normal file
38
app/views/crops/wrangle.html.haml
Normal file
@@ -0,0 +1,38 @@
|
||||
- content_for :title, "Crop Wrangling"
|
||||
|
||||
|
||||
%ul
|
||||
%li= link_to "Requests for new crops", 'http://growstuff.org/posts/skud-20130319-requests-for-new-crops'
|
||||
%li= link_to "Crop wrangler guidelines", "http://wiki.growstuff.org/index.php/Crop_wrangling"
|
||||
%li= link_to "crop-wranglers mailing list", "http://lists.growstuff.org/listinfo/crop-wranglers"
|
||||
%li= link_to "Add Crop", new_crop_path
|
||||
|
||||
%h2 Recently added crops
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @crops, :model => "crops"
|
||||
= will_paginate @crops
|
||||
|
||||
%table.table.table-striped
|
||||
%tr
|
||||
%th System name
|
||||
%th English Wikipedia URL
|
||||
%th Scientific names
|
||||
%th Added by
|
||||
%th When
|
||||
- @crops.each do |c|
|
||||
%tr
|
||||
%td= link_to c.system_name, c
|
||||
%td= link_to c.en_wikipedia_url, c.en_wikipedia_url
|
||||
%td
|
||||
- c.scientific_names.each do |s|
|
||||
= link_to s.scientific_name, s
|
||||
%br/
|
||||
%td= link_to c.creator, c.creator
|
||||
%td
|
||||
= distance_of_time_in_words(c.created_at, Time.zone.now)
|
||||
ago.
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @crops, :model => "crops"
|
||||
= will_paginate @crops
|
||||
@@ -36,9 +36,13 @@
|
||||
.control-group
|
||||
=f.label :location, 'Your location', :class => 'control-label'
|
||||
.controls
|
||||
=f.text_field :location
|
||||
=f.text_field :location, :autocomplete => "off"
|
||||
%span.help-inline This will be displayed on a map. You can be as detailed or vague as you like.
|
||||
|
||||
.control-group
|
||||
=f.label :bio, :class => 'control-label'
|
||||
.controls
|
||||
=f.text_area :bio, :rows => 6, :class => 'input-block-level'
|
||||
|
||||
%h2 Linked accounts
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
- members = Member.interesting.first(6)
|
||||
- if members.present?
|
||||
%h2 Some of our members
|
||||
- cache "interesting_members" do
|
||||
- members = Member.interesting.first(6)
|
||||
- if members.present?
|
||||
%h2 Some of our members
|
||||
|
||||
.visible-desktop.visible-tablet
|
||||
.row-fluid
|
||||
.visible-desktop.visible-tablet
|
||||
.row-fluid
|
||||
- members.each do |m|
|
||||
.span6.homepage-members
|
||||
= render :partial => "members/thumbnail", :locals => { :member => m }
|
||||
|
||||
.visible-phone
|
||||
- members.each do |m|
|
||||
.span6.homepage-members
|
||||
= render :partial => "members/thumbnail", :locals => { :member => m }
|
||||
= render :partial => "members/thumbnail", :locals => { :member => m }
|
||||
|
||||
.visible-phone
|
||||
- members.each do |m|
|
||||
= render :partial => "members/thumbnail", :locals => { :member => m }
|
||||
|
||||
%p.text-right
|
||||
= link_to "View all members »", members_path
|
||||
%p.text-right
|
||||
= link_to "View all members »", members_path
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
Your Stuff (#{current_member.notifications.unread_count})
|
||||
- else
|
||||
Your Stuff
|
||||
%b.caret
|
||||
%b.caret
|
||||
%ul.dropdown-menu
|
||||
%li= link_to "Profile", member_path(current_member)
|
||||
%li= link_to "Gardens", gardens_by_owner_path(:owner => current_member.slug)
|
||||
@@ -44,6 +44,8 @@
|
||||
= link_to("Inbox", notifications_path)
|
||||
|
||||
%li= link_to "Shop", shop_path
|
||||
- if current_member.has_role?(:crop_wrangler)
|
||||
%li= link_to "Crop Wrangling", wrangle_crops_path
|
||||
- if current_member.has_role?(:admin)
|
||||
%li= link_to "Admin", admin_path
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
- cache "member_thumbnail_#{member.id}" do
|
||||
.row-fluid
|
||||
.span3
|
||||
= render :partial => "members/image_with_popover", :locals => { :member => member }
|
||||
.span9
|
||||
%p
|
||||
= link_to member.login_name, member
|
||||
- if ! member.location.blank?
|
||||
%br/
|
||||
%i= member.location
|
||||
- if ! member.plantings.empty?
|
||||
%br/
|
||||
Recently planted:
|
||||
!= member.plantings.first(3).map{|p| link_to p.crop_system_name, p }.join(", ")
|
||||
.member-thumbnail
|
||||
.span3
|
||||
= render :partial => "members/image_with_popover", :locals => { :member => member }
|
||||
.span9
|
||||
%p
|
||||
= link_to member.login_name, member
|
||||
- if ! member.location.blank?
|
||||
%small
|
||||
%br/
|
||||
%i= member.location
|
||||
- if ! member.plantings.empty?
|
||||
%small
|
||||
%br/
|
||||
Recently planted:
|
||||
!= member.plantings.first(3).map{|p| link_to p.crop_system_name, p }.join(", ")
|
||||
|
||||
@@ -53,6 +53,11 @@
|
||||
- if can? :update, @member
|
||||
%p
|
||||
= link_to 'Edit your profile', "edit", :class => 'btn btn-primary'
|
||||
- if @member.bio
|
||||
%h2 Bio
|
||||
:markdown
|
||||
#{ strip_tags @member.bio }
|
||||
%h2 Gardens
|
||||
.tabbable
|
||||
%ul.nav.nav-tabs
|
||||
- first_garden = true
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
- content_for :title, "Edit scientific name"
|
||||
|
||||
%p
|
||||
Added by
|
||||
= @scientific_name.creator
|
||||
= distance_of_time_in_words(@scientific_name.created_at, Time.zone.now)
|
||||
ago.
|
||||
|
||||
= render 'form'
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
.control-group
|
||||
= f.label 'Will trade:', :class => 'control-label'
|
||||
.controls
|
||||
= f.select(:tradable_to, options_for_select(Seed::TRADABLE_TO_VALUES, 'nowhere'))
|
||||
= f.select(:tradable_to,
|
||||
options_for_select(Seed::TRADABLE_TO_VALUES, :selected => @seed.tradable_to || 'nowhere'))
|
||||
%span.help_inline
|
||||
- if current_member.location.blank?
|
||||
Don't forget to
|
||||
|
||||
@@ -55,6 +55,7 @@ Growstuff::Application.configure do
|
||||
config.site_name = "Growstuff (dev)"
|
||||
config.analytics_code = ''
|
||||
config.currency = 'AUD'
|
||||
config.bot_email = "noreply@growstuff.org"
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
|
||||
@@ -86,6 +86,7 @@ Growstuff::Application.configure do
|
||||
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/100594260ns.gif" /></p></noscript>
|
||||
eos
|
||||
config.currency = 'AUD'
|
||||
config.bot_email = "noreply@growstuff.org"
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
|
||||
@@ -82,6 +82,7 @@ Growstuff::Application.configure do
|
||||
config.site_name = "Growstuff (staging)"
|
||||
config.analytics_code = ''
|
||||
config.currency = 'AUD'
|
||||
config.bot_email = "noreply@growstuff.org"
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
|
||||
@@ -46,6 +46,7 @@ Growstuff::Application.configure do
|
||||
config.site_name = "Growstuff (test)"
|
||||
config.analytics_code = ''
|
||||
config.currency = 'AUD'
|
||||
config.bot_email = "noreply@growstuff.org"
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
|
||||
@@ -20,7 +20,10 @@ Growstuff::Application.routes.draw do
|
||||
match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author'
|
||||
|
||||
resources :scientific_names
|
||||
|
||||
match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops'
|
||||
resources :crops
|
||||
|
||||
resources :comments
|
||||
resources :roles
|
||||
resources :forums
|
||||
|
||||
5
db/migrate/20130809012511_add_bio_to_members.rb
Normal file
5
db/migrate/20130809012511_add_bio_to_members.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddBioToMembers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :members, :bio, :text
|
||||
end
|
||||
end
|
||||
5
db/migrate/20130821011352_add_creator_to_crops.rb
Normal file
5
db/migrate/20130821011352_add_creator_to_crops.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddCreatorToCrops < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :crops, :creator_id, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCreatorToScientificName < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :scientific_names, :creator_id, :integer
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130819004549) do
|
||||
ActiveRecord::Schema.define(:version => 20130821073736) do
|
||||
|
||||
create_table "account_types", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
@@ -58,6 +58,7 @@ ActiveRecord::Schema.define(:version => 20130819004549) do
|
||||
t.string "slug"
|
||||
t.integer "parent_id"
|
||||
t.integer "plantings_count"
|
||||
t.integer "creator_id"
|
||||
end
|
||||
|
||||
add_index "crops", ["slug"], :name => "index_crops_on_slug", :unique => true
|
||||
@@ -114,6 +115,7 @@ ActiveRecord::Schema.define(:version => 20130819004549) do
|
||||
t.float "latitude"
|
||||
t.float "longitude"
|
||||
t.boolean "send_notification_email", :default => true
|
||||
t.text "bio"
|
||||
end
|
||||
|
||||
add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
|
||||
@@ -233,6 +235,7 @@ ActiveRecord::Schema.define(:version => 20130819004549) do
|
||||
t.integer "crop_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "creator_id"
|
||||
end
|
||||
|
||||
create_table "seeds", :force => true do |t|
|
||||
|
||||
24
db/seeds.rb
24
db/seeds.rb
@@ -12,9 +12,10 @@ require 'csv'
|
||||
|
||||
def load_data
|
||||
# for all Growstuff sites, including production ones
|
||||
load_crops
|
||||
load_roles
|
||||
load_basic_account_types
|
||||
create_cropbot
|
||||
load_crops
|
||||
|
||||
# for development environments only
|
||||
if Rails.env.development?
|
||||
@@ -27,17 +28,18 @@ def load_data
|
||||
puts "Done!"
|
||||
end
|
||||
|
||||
|
||||
def load_crops
|
||||
puts "Loading crops..."
|
||||
CSV.foreach(Rails.root.join('db', 'seeds', 'crops.csv')) do |row|
|
||||
system_name,scientific_name,en_wikipedia_url = row
|
||||
@crop = Crop.create(
|
||||
:system_name => system_name,
|
||||
:en_wikipedia_url => en_wikipedia_url
|
||||
:en_wikipedia_url => en_wikipedia_url,
|
||||
:creator_id => @cropbot_user.id
|
||||
)
|
||||
@crop.scientific_names.create(
|
||||
:scientific_name => scientific_name
|
||||
:scientific_name => scientific_name,
|
||||
:creator_id => @cropbot_user.id
|
||||
)
|
||||
end
|
||||
puts "Finished loading crops"
|
||||
@@ -102,6 +104,20 @@ def load_admin_users
|
||||
@wrangler_user.save!
|
||||
end
|
||||
|
||||
def create_cropbot
|
||||
@cropbot_user = Member.create(
|
||||
:login_name => "cropbot",
|
||||
:email => Growstuff::Application.config.bot_email,
|
||||
:password => SecureRandom.urlsafe_base64(64),
|
||||
:tos_agreement => true
|
||||
)
|
||||
@cropbot_user.confirm!
|
||||
@cropbot_user.roles << @wrangler
|
||||
@cropbot_user.save!
|
||||
@cropbot_user.account.account_type = AccountType.find_by_name("Staff")
|
||||
@cropbot_user.account.save
|
||||
end
|
||||
|
||||
def load_paid_account_types
|
||||
puts "Adding 'paid' and 'seed' account types..."
|
||||
@paid_account = AccountType.create!(
|
||||
|
||||
@@ -128,9 +128,24 @@ namespace :growstuff do
|
||||
Crop.find_each do |c|
|
||||
Crop.reset_counters c.id, :plantings
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
desc "August 2013: set default creator on existing crops"
|
||||
task :set_default_crop_creator => :environment do
|
||||
|
||||
cropbot = Member.find_by_login_name("cropbot")
|
||||
raise "cropbot not found: create cropbot member on site or run rake db:seed" unless cropbot
|
||||
cropbot.account.account_type = AccountType.find_by_name("Staff") # set this just because it's nice
|
||||
cropbot.account.save
|
||||
Crop.find_each do |crop|
|
||||
crop.creator = cropbot
|
||||
crop.save
|
||||
end
|
||||
ScientificName.find_each do |sn|
|
||||
sn.creator = cropbot
|
||||
sn.save
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,3 +8,6 @@
|
||||
|
||||
echo "2013-08-18 - reset crop planting counts"
|
||||
rake growstuff:oneoff:reset_crop_plantings_count
|
||||
|
||||
echo "2013-08-21 - set default crop creator"
|
||||
rake growstuff:oneoff:set_default_crop_creator
|
||||
|
||||
@@ -11,6 +11,14 @@ describe CropsController do
|
||||
}
|
||||
end
|
||||
|
||||
describe "GET crop wrangler homepage" do
|
||||
it 'fetches the crop wrangler homepage' do
|
||||
get :wrangle
|
||||
response.should be_success
|
||||
response.should render_template("crops/wrangle")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET RSS feed" do
|
||||
it "returns an RSS feed" do
|
||||
get :index, :format => "rss"
|
||||
|
||||
@@ -3,6 +3,7 @@ FactoryGirl.define do
|
||||
factory :crop do
|
||||
system_name "Magic bean"
|
||||
en_wikipedia_url "http://en.wikipedia.org/wiki/Magic_bean"
|
||||
creator
|
||||
|
||||
factory :tomato do
|
||||
system_name "Tomato"
|
||||
|
||||
@@ -2,18 +2,23 @@ FactoryGirl.define do
|
||||
sequence(:email) { |n| "member#{n}@example.com" }
|
||||
sequence(:login_name) { |n| "member#{n}" }
|
||||
|
||||
factory :member, aliases: [:author, :owner, :sender, :recipient] do
|
||||
factory :member, aliases: [:author, :owner, :sender, :recipient, :creator] do
|
||||
login_name { generate(:login_name) }
|
||||
password 'password1'
|
||||
email { generate(:email) }
|
||||
tos_agreement true
|
||||
confirmed_at Time.now
|
||||
show_email false
|
||||
bio 'I love seeds'
|
||||
|
||||
factory :no_tos_member do
|
||||
tos_agreement false
|
||||
end
|
||||
|
||||
factory :no_bio_member do
|
||||
bio nil
|
||||
end
|
||||
|
||||
factory :unconfirmed_member do
|
||||
confirmed_at nil
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ FactoryGirl.define do
|
||||
factory :scientific_name do
|
||||
association :crop, factory: :crop
|
||||
scientific_name "Beanus Magicus"
|
||||
creator
|
||||
|
||||
factory :zea_mays do
|
||||
association :crop, factory: :maize
|
||||
|
||||
@@ -23,6 +23,11 @@ describe Crop do
|
||||
@crop.to_s.should == 'Tomato'
|
||||
"#{@crop}".should == 'Tomato'
|
||||
end
|
||||
|
||||
it 'has a creator' do
|
||||
@crop.save
|
||||
@crop.creator.should be_an_instance_of Member
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid data' do
|
||||
|
||||
@@ -24,6 +24,12 @@ describe 'member' do
|
||||
@member.slug.should match(/member\d+/)
|
||||
end
|
||||
|
||||
it 'has a bio' do
|
||||
@member.bio = 'I love seeds'
|
||||
@member.save
|
||||
@member.bio.should eq 'I love seeds'
|
||||
end
|
||||
|
||||
it 'should have a default garden' do
|
||||
@member.save
|
||||
@member.gardens.count.should == 1
|
||||
|
||||
@@ -16,6 +16,11 @@ describe ScientificName do
|
||||
@sn2 = ScientificName.find_by_scientific_name('Zea mays')
|
||||
@sn2.crop.system_name.should == "Maize"
|
||||
end
|
||||
|
||||
it 'has a creator' do
|
||||
@sn.save
|
||||
@sn.creator.should be_an_instance_of Member
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid data' do
|
||||
|
||||
@@ -9,6 +9,10 @@ describe "crops/edit" do
|
||||
render
|
||||
end
|
||||
|
||||
it "shows the creator" do
|
||||
rendered.should contain "Added by #{@crop.creator} less than a minute ago."
|
||||
end
|
||||
|
||||
it "renders the edit crop form" do
|
||||
assert_select "form", :action => crops_path(@crop), :method => "post" do
|
||||
assert_select "input#crop_system_name", :name => "crop[system_name]"
|
||||
|
||||
35
spec/views/crops/wrangle.html.haml_spec.rb
Normal file
35
spec/views/crops/wrangle.html.haml_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "crops/wrangle" do
|
||||
before(:each) do
|
||||
@member = FactoryGirl.create(:crop_wrangling_member)
|
||||
controller.stub(:current_user) { @member }
|
||||
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([ @tomato, @maize ])
|
||||
end
|
||||
assign(:crops, crops)
|
||||
end
|
||||
|
||||
it 'contains handy links for wranglers' do
|
||||
render
|
||||
rendered.should contain "Crop wrangler guidelines"
|
||||
rendered.should contain "mailing list"
|
||||
end
|
||||
|
||||
it 'has a link to add a crop' do
|
||||
render
|
||||
assert_select "a", :href => new_crop_path
|
||||
end
|
||||
|
||||
it "renders a list of crops" do
|
||||
render
|
||||
assert_select "a", :text => "Maize"
|
||||
assert_select "a", :text => "Tomato"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -40,15 +40,23 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do
|
||||
it 'has a heading' do
|
||||
assert_select "h2", "Profile details"
|
||||
end
|
||||
|
||||
it 'shows show_email checkbox' do
|
||||
assert_select "input[id=member_show_email][type=checkbox]"
|
||||
end
|
||||
|
||||
it "contains a gravatar icon" do
|
||||
assert_select "img", :src => /gravatar\.com\/avatar/
|
||||
end
|
||||
|
||||
it 'contains a link to gravatar.com' do
|
||||
assert_select "a", :href => /gravatar\.com/
|
||||
end
|
||||
|
||||
it 'shows bio field' do
|
||||
assert_select "textarea[id=member_bio]"
|
||||
end
|
||||
|
||||
it 'shows location field' do
|
||||
assert_select "input[id=member_location][type=text]"
|
||||
end
|
||||
|
||||
@@ -12,6 +12,11 @@ describe "members/show" do
|
||||
render
|
||||
end
|
||||
|
||||
it "shows the bio" do
|
||||
assert_select "h2", "Bio"
|
||||
rendered.should contain @member.bio
|
||||
end
|
||||
|
||||
it "shows account creation date" do
|
||||
@time = @member.created_at
|
||||
rendered.should contain "Member since"
|
||||
@@ -27,6 +32,17 @@ describe "members/show" do
|
||||
end
|
||||
end
|
||||
|
||||
context 'no bio' do
|
||||
before(:each) do
|
||||
@member = FactoryGirl.create(:no_bio_member)
|
||||
render
|
||||
end
|
||||
|
||||
it "doesn't show the bio" do
|
||||
rendered.should_not contain "Bio"
|
||||
end
|
||||
end
|
||||
|
||||
context 'twitter' do
|
||||
context "no twitter" do
|
||||
it "doesn't show twitter link" do
|
||||
|
||||
@@ -12,6 +12,10 @@ describe "scientific_names/edit" do
|
||||
render
|
||||
end
|
||||
|
||||
it "shows the creator" do
|
||||
rendered.should contain "Added by #{@scientific_name.creator} less than a minute ago."
|
||||
end
|
||||
|
||||
it "renders the edit scientific_name form" do
|
||||
assert_select "form", :action => scientific_names_path(@scientific_name), :method => "post" do
|
||||
assert_select "input#scientific_name_scientific_name", :name => "scientific_name[scientific_name]"
|
||||
|
||||
@@ -19,4 +19,11 @@ describe "seeds/edit" do
|
||||
assert_select "select#seed_tradable_to", :name => "seed[tradable_to]"
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't revert tradable_to to nowhere" do
|
||||
@seed = FactoryGirl.create(:tradable_seed, :owner => @member)
|
||||
@seed.tradable_to.should_not eq "nowhere"
|
||||
render
|
||||
assert_select "option[selected=selected]", :text => @seed.tradable_to
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user