mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 21:56:55 -04:00
implement auto suggest on new seed page
This commit is contained in:
@@ -16,7 +16,6 @@ jQuery ->
|
||||
el.autocomplete
|
||||
minLength: 1,
|
||||
source: el.attr( 'data-source-url' ),
|
||||
autoFocus: true,
|
||||
focus: ( event, ui ) ->
|
||||
el.val( ui.item.name )
|
||||
id.val( ui.item.id )
|
||||
|
||||
@@ -7,20 +7,21 @@
|
||||
%li= msg
|
||||
|
||||
.control-group
|
||||
= f.label 'Crop:', :class => 'control-label'
|
||||
.controls= collection_select(:seed, :crop_id, Crop.all, :id, :name, :selected => @seed.crop_id || @crop.id)
|
||||
= f.label :crop, 'Crop:', :class => 'control-label'
|
||||
.controls
|
||||
= auto_suggest @seed, :crop
|
||||
.control-group
|
||||
= f.label 'Quantity:', :class => 'control-label'
|
||||
= f.label :quantity, 'Quantity:', :class => 'control-label'
|
||||
.controls
|
||||
= f.number_field :quantity, :class => 'input-small'
|
||||
.control-group
|
||||
= f.label 'Plant before:', :class => 'control-label'
|
||||
= f.label :plant_before, 'Plant before:', :class => 'control-label'
|
||||
.controls= f.text_field :plant_before, :value => @seed.plant_before ? @seed.plant_before.to_s(:ymd) : '', :class => 'add-datepicker'
|
||||
.control-group
|
||||
= f.label 'Description:', :class => 'control-label'
|
||||
= f.label :description, 'Description:', :class => 'control-label'
|
||||
.controls= f.text_area :description, :rows => 6
|
||||
.control-group
|
||||
= f.label 'Will trade:', :class => 'control-label'
|
||||
= f.label :tradable_to, 'Will trade:', :class => 'control-label'
|
||||
.controls
|
||||
= f.select(:tradable_to,
|
||||
options_for_select(Seed::TRADABLE_TO_VALUES, :selected => @seed.tradable_to || 'nowhere'))
|
||||
|
||||
28
spec/features/adding_a_seed_spec.rb
Normal file
28
spec/features/adding_a_seed_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature "Harvesting a crop", :js => true do
|
||||
let(:member) { FactoryGirl.create(:member) }
|
||||
let!(:maize) { FactoryGirl.create(:maize) }
|
||||
|
||||
background do
|
||||
login_as(member)
|
||||
visit '/seeds/new'
|
||||
end
|
||||
|
||||
it_behaves_like "crop suggest", "seed", "crop"
|
||||
|
||||
scenario "Adding a new seed", :js => true do
|
||||
fill_autocomplete "crop", :with => "m"
|
||||
select_from_autocomplete "maize"
|
||||
within "form#new_seed" do
|
||||
fill_in "Quantity:", :with => 42
|
||||
fill_in "Plant before:", :with => "2014-06-15"
|
||||
fill_in "Description", :with => "It's killer."
|
||||
select "internationally", :from => "Will trade:"
|
||||
click_button "Save"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Successfully added maize seed to your stash"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,15 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature "Harvesting a crop", :js => true do
|
||||
let(:member) { FactoryGirl.create(:member) }
|
||||
let!(:maize) { FactoryGirl.create(:maize) }
|
||||
let(:member) { FactoryGirl.create(:member) }
|
||||
let!(:maize) { FactoryGirl.create(:maize) }
|
||||
|
||||
background do
|
||||
login_as(member)
|
||||
visit '/harvests/new'
|
||||
end
|
||||
|
||||
it_behaves_like "crop suggest", "harvest"
|
||||
it_behaves_like "crop suggest", "harvest", "crop"
|
||||
|
||||
scenario "Creating a new harvest", :js => true do
|
||||
fill_autocomplete "crop", :with => "m"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature "Planting a crop", :js => true do
|
||||
let(:member) { FactoryGirl.create(:member) }
|
||||
let!(:maize) { FactoryGirl.create(:maize) }
|
||||
let(:member) { FactoryGirl.create(:member) }
|
||||
let!(:maize) { FactoryGirl.create(:maize) }
|
||||
|
||||
background do
|
||||
login_as(member)
|
||||
visit '/plantings/new'
|
||||
end
|
||||
|
||||
it_behaves_like "crop suggest", "planting"
|
||||
it_behaves_like "crop suggest", "planting", "crop"
|
||||
|
||||
scenario "Creating a new planting", :js => true do
|
||||
fill_autocomplete "crop", :with => "m"
|
||||
|
||||
@@ -3,6 +3,8 @@ require 'spec_helper'
|
||||
shared_examples "crop suggest" do |resource|
|
||||
let!(:popcorn) { FactoryGirl.create(:popcorn) }
|
||||
let!(:pear) { FactoryGirl.create(:pear) }
|
||||
let!(:tomato) { FactoryGirl.create(:tomato) }
|
||||
let!(:roma) { FactoryGirl.create(:roma) }
|
||||
|
||||
scenario "Typing in the crop name displays suggestions" do
|
||||
within "form#new_#{resource}" do
|
||||
@@ -33,4 +35,22 @@ shared_examples "crop suggest" do |resource|
|
||||
expect(find_field("crop").value).to eq("p")
|
||||
end
|
||||
|
||||
scenario "Searching for a crop casts a wide net on results" do
|
||||
within "form#new_#{resource}" do
|
||||
fill_autocomplete "crop", :with => "to"
|
||||
end
|
||||
|
||||
expect(page).to have_content("tomato")
|
||||
expect(page).to have_content("roma tomato")
|
||||
end
|
||||
|
||||
scenario "Submitting a crop that doesn't exist in the database produces a meaningful error" do
|
||||
within "form#new_#{resource}" do
|
||||
fill_autocomplete "crop", :with => "Ryan Gosling"
|
||||
click_button "Save"
|
||||
end
|
||||
|
||||
expect(page).to have_content("That's not in our database.")
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user