mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-04 23:17:30 -05:00
Display crop hierarchy (recursively!)
This commit is contained in:
@@ -27,6 +27,7 @@ class CropsController < ApplicationController
|
||||
|
||||
# GET /crops/hierarchy
|
||||
def hierarchy
|
||||
@crops = Crop.toplevel
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
|
||||
7
app/views/crops/_hierarchy.html.haml
Normal file
7
app/views/crops/_hierarchy.html.haml
Normal file
@@ -0,0 +1,7 @@
|
||||
%ul
|
||||
- display_crops.each do |c|
|
||||
%li
|
||||
= link_to c, c
|
||||
- if c.varieties.present?
|
||||
- c.varieties.each do |v|
|
||||
= render :partial => 'hierarchy', :locals => { :display_crops => [ v ] }
|
||||
@@ -4,3 +4,5 @@
|
||||
This page shows the hierarchical tree of all crops in our
|
||||
= succeed "." do
|
||||
= link_to "crops database", crops_path
|
||||
|
||||
= render :partial => "hierarchy", :locals => { :display_crops => @crops }
|
||||
|
||||
15
spec/views/crops/hierarchy.html.haml_spec.rb
Normal file
15
spec/views/crops/hierarchy.html.haml_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "crops/hierarchy" do
|
||||
before(:each) do
|
||||
controller.stub(:current_user) { nil }
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@roma = FactoryGirl.create(:crop, :system_name => 'Roma tomato', :parent => @tomato)
|
||||
assign(:crops, [@tomato, @roma])
|
||||
render
|
||||
end
|
||||
|
||||
it "shows crop hierarchy" do
|
||||
assert_select "ul>li>ul>li", :text => @roma.system_name
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user