Display crop hierarchy (recursively!)

This commit is contained in:
Skud
2013-09-02 12:01:58 +10:00
parent 4dbfecd315
commit 995f9b2d60
4 changed files with 25 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ class CropsController < ApplicationController
# GET /crops/hierarchy
def hierarchy
@crops = Crop.toplevel
respond_to do |format|
format.html
end

View 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 ] }

View File

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

View 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