diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 29f15543f..29725d959 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -27,6 +27,7 @@ class CropsController < ApplicationController # GET /crops/hierarchy def hierarchy + @crops = Crop.toplevel respond_to do |format| format.html end diff --git a/app/views/crops/_hierarchy.html.haml b/app/views/crops/_hierarchy.html.haml new file mode 100644 index 000000000..54ec68d7e --- /dev/null +++ b/app/views/crops/_hierarchy.html.haml @@ -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 ] } diff --git a/app/views/crops/hierarchy.html.haml b/app/views/crops/hierarchy.html.haml index 27abb46cd..59995ab51 100644 --- a/app/views/crops/hierarchy.html.haml +++ b/app/views/crops/hierarchy.html.haml @@ -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 } diff --git a/spec/views/crops/hierarchy.html.haml_spec.rb b/spec/views/crops/hierarchy.html.haml_spec.rb new file mode 100644 index 000000000..5af869938 --- /dev/null +++ b/spec/views/crops/hierarchy.html.haml_spec.rb @@ -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