From 9da92c8f71e65d51ed387da5dc2a9b2f9bb98239 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 11 Nov 2013 11:18:14 +1100 Subject: [PATCH] Make growstuff HAML extensions case insensitive --- lib/haml/filters/growstuff_markdown.rb | 3 ++- spec/lib/haml/filters/growstuff_markdown_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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