diff --git a/lib/haml/filters/growstuff_markdown.rb b/lib/haml/filters/growstuff_markdown.rb
index e438ac271..35333a256 100644
--- a/lib/haml/filters/growstuff_markdown.rb
+++ b/lib/haml/filters/growstuff_markdown.rb
@@ -9,7 +9,8 @@ module Haml::Filters
# turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato)
expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m|
crop_str = $1
- crop = Crop.find_by_name(crop_str)
+ # find crop case-insensitively
+ crop = Crop.where('lower(name) = ?', crop_str.downcase).first
if crop
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
"[#{crop_str}](#{url})"
diff --git a/spec/lib/haml/filters/growstuff_markdown_spec.rb b/spec/lib/haml/filters/growstuff_markdown_spec.rb
index 6218c54d4..566740307 100644
--- a/spec/lib/haml/filters/growstuff_markdown_spec.rb
+++ b/spec/lib/haml/filters/growstuff_markdown_spec.rb
@@ -6,9 +6,13 @@ def input_link(name)
return "[#{name}](crop)"
end
-def output_link(crop)
+def output_link(crop, name=nil)
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
- return "#{crop.name}"
+ if name
+ return "#{name}"
+ else
+ return "#{crop.name}"
+ end
end
describe 'Haml::Filters::Growstuff_Markdown' do
@@ -42,4 +46,10 @@ describe 'Haml::Filters::Growstuff_Markdown' do
rendered.should match /foo<\/strong>/
end
+ it "finds crops case insensitively" do
+ @crop = FactoryGirl.create(:crop, :name => 'tomato')
+ rendered = Haml::Filters::GrowstuffMarkdown.render(input_link('ToMaTo'))
+ rendered.should match /#{output_link(@crop, 'ToMaTo')}/
+ end
+
end