mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-24 17:54:59 -04:00
@@ -45,6 +45,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|
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -44,6 +44,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
|
||||
|
||||
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
|
||||
@@ -233,6 +234,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
|
||||
|
||||
@@ -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,7 +2,7 @@ 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) }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]"
|
||||
|
||||
@@ -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]"
|
||||
|
||||
Reference in New Issue
Block a user