Merge branch 'Skud-scinames' into dev

This commit is contained in:
Skud
2014-07-22 11:23:23 +10:00
6 changed files with 44 additions and 4 deletions

View File

@@ -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)

View File

@@ -81,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 }
@@ -99,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.' }

View File

@@ -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

View File

@@ -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'

View File

@@ -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

View File

@@ -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