From 9a037796ce19c13a87828367bc50b0abc023b869 Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Tue, 27 Sep 2011 21:16:49 +0100 Subject: [PATCH 01/10] experimenting with Gemfile to get mysql to connect --- Gemfile | 4 +++- Gemfile.lock | 42 +++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index f3d4838..f3f5a76 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "http://rubygems.org" gem "rails", "3.0.10" -gem "mysql", "2.8.1" +gem "mysql2", "~> 0.2.1" gem "simple_form", "1.5.0" gem "omniauth", "0.2.6" gem "paper_trail", "1.6.4" @@ -22,3 +22,5 @@ group :test do gem "launchy" gem "escape_utils", "0.1.9" end + +# gem "rake", "0.8.7" diff --git a/Gemfile.lock b/Gemfile.lock index 80da368..061aebf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,16 +39,15 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (>= 0.0.3) - childprocess (0.0.9) - ffi (~> 0.6.3) - columnize (0.3.1) - configuration (1.1.0) - culerity (0.2.12) + childprocess (0.2.2) + ffi (~> 1.0.6) + columnize (0.3.4) + culerity (0.2.15) database_cleaner (0.5.2) erubis (2.6.6) abstract (>= 1.0.0) escape_utils (0.1.9) - factory_girl (1.3.2) + factory_girl (1.3.3) factory_girl_rails (1.0) factory_girl (~> 1.3) rails (>= 3.0.0.beta4) @@ -60,15 +59,12 @@ GEM rack (< 2, >= 1.1.0) faraday_middleware (0.6.5) faraday (~> 0.6.0) - ffi (0.6.3) - rake (>= 0.8.7) + ffi (1.0.9) hashie (1.0.0) i18n (0.5.0) - json_pure (1.4.6) - launchy (0.3.7) - configuration (>= 0.0.5) - rake (>= 0.8.1) - linecache19 (0.5.11) + json_pure (1.6.1) + launchy (2.0.3) + linecache19 (0.5.12) ruby_core_source (>= 0.1.4) mail (2.2.19) activesupport (>= 2.3.6) @@ -81,9 +77,9 @@ GEM multi_json (1.0.3) multi_xml (0.2.2) multipart-post (1.1.3) - mysql (2.8.1) + mysql2 (0.2.13) net-ldap (0.2.2) - nokogiri (1.4.3.1) + nokogiri (1.4.7) oa-basic (0.2.6) oa-core (= 0.2.6) rest-client (~> 1.6.0) @@ -126,7 +122,7 @@ GEM activerecord (>= 2.3) polyglot (0.3.2) pyu-ruby-sasl (0.0.3.3) - rack (1.2.3) + rack (1.2.4) rack-mount (0.6.14) rack (>= 1.0.0) rack-openid (1.3.1) @@ -148,12 +144,12 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (0.9.2) + rake (0.8.7) rdoc (3.9.4) redcarpet (2.0.0b5) rest-client (1.6.7) mime-types (>= 1.16) - ruby-debug-base19 (0.11.24) + ruby-debug-base19 (0.11.25) columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby_core_source (>= 0.1.4) @@ -164,13 +160,13 @@ GEM ruby-openid (2.1.8) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) - ruby_core_source (0.1.4) + ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) rubyntlm (0.1.1) rubyzip (0.9.4) - selenium-webdriver (0.0.29) - childprocess (>= 0.0.7) - ffi (~> 0.6.3) + selenium-webdriver (2.7.0) + childprocess (>= 0.2.1) + ffi (>= 1.0.7) json_pure rubyzip shoulda (2.11.3) @@ -203,7 +199,7 @@ DEPENDENCIES faker (= 0.9.5) launchy mocha (= 0.9.8) - mysql (= 2.8.1) + mysql2 (~> 0.2.1) omniauth (= 0.2.6) paper_trail (= 1.6.4) rails (= 3.0.10) From a37971cd4e4ee0a622d779141f8ce6d12090c952 Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Tue, 27 Sep 2011 21:20:52 +0100 Subject: [PATCH 02/10] mysql2 version fixed for clarity --- Gemfile | 4 +--- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index f3f5a76..ecb87ec 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "http://rubygems.org" gem "rails", "3.0.10" -gem "mysql2", "~> 0.2.1" +gem "mysql2", "0.2.13" gem "simple_form", "1.5.0" gem "omniauth", "0.2.6" gem "paper_trail", "1.6.4" @@ -22,5 +22,3 @@ group :test do gem "launchy" gem "escape_utils", "0.1.9" end - -# gem "rake", "0.8.7" diff --git a/Gemfile.lock b/Gemfile.lock index 061aebf..08b6b1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,7 +144,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (0.8.7) + rake (0.9.2) rdoc (3.9.4) redcarpet (2.0.0b5) rest-client (1.6.7) @@ -199,7 +199,7 @@ DEPENDENCIES faker (= 0.9.5) launchy mocha (= 0.9.8) - mysql2 (~> 0.2.1) + mysql2 (= 0.2.13) omniauth (= 0.2.6) paper_trail (= 1.6.4) rails (= 3.0.10) From e5dcf0c98d7ea5904a4baad8743cabb4baccd0de Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Thu, 29 Sep 2011 00:46:25 +0100 Subject: [PATCH 03/10] need to specify older version of rake --- Gemfile | 2 ++ Gemfile.lock | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ecb87ec..23ba275 100644 --- a/Gemfile +++ b/Gemfile @@ -22,3 +22,5 @@ group :test do gem "launchy" gem "escape_utils", "0.1.9" end + +gem "rake", "0.8.7" diff --git a/Gemfile.lock b/Gemfile.lock index 08b6b1c..2743bf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,7 +144,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (0.9.2) + rake (0.8.7) rdoc (3.9.4) redcarpet (2.0.0b5) rest-client (1.6.7) @@ -203,6 +203,7 @@ DEPENDENCIES omniauth (= 0.2.6) paper_trail (= 1.6.4) rails (= 3.0.10) + rake (= 0.8.7) redcarpet (~> 2.0.0b5) ruby-debug19 shoulda (= 2.11.3) From 9a5bc5b8d5792c1a1bd07be83d7f48b0b32742ed Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Fri, 30 Sep 2011 13:32:15 +0100 Subject: [PATCH 04/10] database cleaner updated to work with mysql2 - all tests now pass, which helps --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 23ba275..f6435df 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ group :test do gem "factory_girl_rails", "1.0" gem "shoulda", "2.11.3" gem "capybara", "0.3.9" - gem "database_cleaner", "0.5.2" + gem "database_cleaner", "0.6.0" gem "mocha", "0.9.8", :require => false gem "faker", "0.9.5" gem "timecop", "0.3.5" diff --git a/Gemfile.lock b/Gemfile.lock index 2743bf9..9285fcf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,7 +43,7 @@ GEM ffi (~> 1.0.6) columnize (0.3.4) culerity (0.2.15) - database_cleaner (0.5.2) + database_cleaner (0.6.0) erubis (2.6.6) abstract (>= 1.0.0) escape_utils (0.1.9) @@ -186,14 +186,14 @@ GEM multi_json (~> 1.0.0) multi_xml (~> 0.2.0) simple_oauth (~> 0.1.5) - tzinfo (0.3.29) + tzinfo (0.3.30) PLATFORMS ruby DEPENDENCIES capybara (= 0.3.9) - database_cleaner (= 0.5.2) + database_cleaner (= 0.6.0) escape_utils (= 0.1.9) factory_girl_rails (= 1.0) faker (= 0.9.5) From 91f8eea16f8fa662d4e965bce1babf65e53ebb5f Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Sat, 1 Oct 2011 08:18:47 +0100 Subject: [PATCH 05/10] Basic wiki leading straight to proposal creation for unrecognised names --- app/controllers/proposals_controller.rb | 10 +++++++- app/helpers/application_helper.rb | 9 +++++++ config/routes.rb | 1 + db/seeds.rb | 10 ++++---- test/unit/helpers/application_helper_test.rb | 27 ++++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 66545a6..5edc971 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -1,3 +1,5 @@ +require 'uri' + class ProposalsController < ApplicationController before_filter :authenticate_user!, :except => [:index, :show] @@ -18,6 +20,12 @@ def new @proposal = Proposal.new end + def moot + @proposal = Proposal.new + @proposal.title = URI.unescape params[:title] + render :new + end + def create @proposal = current_user.proposals.new(params[:proposal]) if @proposal.save @@ -36,7 +44,7 @@ def update if @proposal.update_attributes(params[:proposal]) redirect_to proposal_path(@proposal) else - render :edit + render :edit end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fe2f888..9c00466 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,5 @@ require 'redcarpet' +require 'uri' module ApplicationHelper def render_page_title @@ -32,8 +33,16 @@ def avatar_url(user, bigger=false) end end + def wikiize(text) + names = {} + User.all.each {|user| names[user.name] = link_to(user.name, user) } + Proposal.all.each {|proposal| names[proposal.title] = link_to(proposal.title, proposal) } + text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "moot", :title => URI.escape($1)}) } + end + def markdown(text) if text + text = wikiize(text) markdown_parser.render(text).html_safe else nil diff --git a/config/routes.rb b/config/routes.rb index 1dfd10c..126e730 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Vestibule::Application.routes.draw do resources :users, :only => [:show, :edit, :update] + get "/proposals/moot" resources :proposals, :except => [:destroy] do resources :suggestions, :only => [:create] member do diff --git a/db/seeds.rb b/db/seeds.rb index 76909c2..1da96e0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,8 +6,8 @@ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first) -def user(name) - User.create!(:name => name, :twitter_nickname => name) +def user(name, nickname=nil) + User.create!(:name => name, :twitter_nickname => nickname || name) end def suggestions_for(proposal, suggestions) @@ -19,10 +19,10 @@ def suggestions_for(proposal, suggestions) end end -alice = user("alice") +alice = user("Alice", "alice") bob = user("bob") -charlie = user("charlie") -daniel = user("daniel") +charlie = user("Charlie Parker", "charlie") +daniel = user("Daniel Boone", "daniel") a = alice.proposals.create :title => "Fake it till you make it", :description => <<-EOS I've written a few things recently which work against 3rd party HTTP API's recently. diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 595fd91..d36ce8f 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -22,4 +22,31 @@ class ApplicationHelperTest < ActionView::TestCase end end end + + context "wiki" do + context "for a single user" do + setup do + @user = Factory(:user, :twitter_nickname => "rdrake98", :name => "Richard Drake") + end + + should "turn into link" do + assert_equal link_to("Richard Drake", "/users/rdrake98"), wikiize("[[Richard Drake]]") + end + end + + context "for a single proposal" do + setup do + @user = Factory(:proposal, :title => "My One and Only") + end + + should "turn into link" do + assert_equal link_to("My One and Only", "/proposals/1"), wikiize("[[My One and Only]]") + assert_equal link_to("Her Latest Idea", "/proposals/moot?title=Her%2520Latest%2520Idea"), wikiize("[[Her Latest Idea]]") + assert_equal( + "I prefer Her Latest Idea to My One and Only.", + wikiize("I prefer [[Her Latest Idea]] to [[My One and Only]].") + ) + end + end + end end From c1336122cb26a1e6e4009ca76fcf1e8a20d323ba Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Mon, 3 Oct 2011 14:36:58 +0100 Subject: [PATCH 06/10] Reverting to original Gemfile --- Gemfile | 6 ++---- Gemfile.lock | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index f6435df..f3d4838 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "http://rubygems.org" gem "rails", "3.0.10" -gem "mysql2", "0.2.13" +gem "mysql", "2.8.1" gem "simple_form", "1.5.0" gem "omniauth", "0.2.6" gem "paper_trail", "1.6.4" @@ -12,7 +12,7 @@ group :test do gem "factory_girl_rails", "1.0" gem "shoulda", "2.11.3" gem "capybara", "0.3.9" - gem "database_cleaner", "0.6.0" + gem "database_cleaner", "0.5.2" gem "mocha", "0.9.8", :require => false gem "faker", "0.9.5" gem "timecop", "0.3.5" @@ -22,5 +22,3 @@ group :test do gem "launchy" gem "escape_utils", "0.1.9" end - -gem "rake", "0.8.7" diff --git a/Gemfile.lock b/Gemfile.lock index 9285fcf..80da368 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,15 +39,16 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (>= 0.0.3) - childprocess (0.2.2) - ffi (~> 1.0.6) - columnize (0.3.4) - culerity (0.2.15) - database_cleaner (0.6.0) + childprocess (0.0.9) + ffi (~> 0.6.3) + columnize (0.3.1) + configuration (1.1.0) + culerity (0.2.12) + database_cleaner (0.5.2) erubis (2.6.6) abstract (>= 1.0.0) escape_utils (0.1.9) - factory_girl (1.3.3) + factory_girl (1.3.2) factory_girl_rails (1.0) factory_girl (~> 1.3) rails (>= 3.0.0.beta4) @@ -59,12 +60,15 @@ GEM rack (< 2, >= 1.1.0) faraday_middleware (0.6.5) faraday (~> 0.6.0) - ffi (1.0.9) + ffi (0.6.3) + rake (>= 0.8.7) hashie (1.0.0) i18n (0.5.0) - json_pure (1.6.1) - launchy (2.0.3) - linecache19 (0.5.12) + json_pure (1.4.6) + launchy (0.3.7) + configuration (>= 0.0.5) + rake (>= 0.8.1) + linecache19 (0.5.11) ruby_core_source (>= 0.1.4) mail (2.2.19) activesupport (>= 2.3.6) @@ -77,9 +81,9 @@ GEM multi_json (1.0.3) multi_xml (0.2.2) multipart-post (1.1.3) - mysql2 (0.2.13) + mysql (2.8.1) net-ldap (0.2.2) - nokogiri (1.4.7) + nokogiri (1.4.3.1) oa-basic (0.2.6) oa-core (= 0.2.6) rest-client (~> 1.6.0) @@ -122,7 +126,7 @@ GEM activerecord (>= 2.3) polyglot (0.3.2) pyu-ruby-sasl (0.0.3.3) - rack (1.2.4) + rack (1.2.3) rack-mount (0.6.14) rack (>= 1.0.0) rack-openid (1.3.1) @@ -144,12 +148,12 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (0.8.7) + rake (0.9.2) rdoc (3.9.4) redcarpet (2.0.0b5) rest-client (1.6.7) mime-types (>= 1.16) - ruby-debug-base19 (0.11.25) + ruby-debug-base19 (0.11.24) columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby_core_source (>= 0.1.4) @@ -160,13 +164,13 @@ GEM ruby-openid (2.1.8) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) - ruby_core_source (0.1.5) + ruby_core_source (0.1.4) archive-tar-minitar (>= 0.5.2) rubyntlm (0.1.1) rubyzip (0.9.4) - selenium-webdriver (2.7.0) - childprocess (>= 0.2.1) - ffi (>= 1.0.7) + selenium-webdriver (0.0.29) + childprocess (>= 0.0.7) + ffi (~> 0.6.3) json_pure rubyzip shoulda (2.11.3) @@ -186,24 +190,23 @@ GEM multi_json (~> 1.0.0) multi_xml (~> 0.2.0) simple_oauth (~> 0.1.5) - tzinfo (0.3.30) + tzinfo (0.3.29) PLATFORMS ruby DEPENDENCIES capybara (= 0.3.9) - database_cleaner (= 0.6.0) + database_cleaner (= 0.5.2) escape_utils (= 0.1.9) factory_girl_rails (= 1.0) faker (= 0.9.5) launchy mocha (= 0.9.8) - mysql2 (= 0.2.13) + mysql (= 2.8.1) omniauth (= 0.2.6) paper_trail (= 1.6.4) rails (= 3.0.10) - rake (= 0.8.7) redcarpet (~> 2.0.0b5) ruby-debug19 shoulda (= 2.11.3) From b89452d7f347790af972961b36b6bdbdc171f35c Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Mon, 3 Oct 2011 12:20:53 +0100 Subject: [PATCH 07/10] new?title= instead of moot?title= --- app/controllers/proposals_controller.rb | 8 ++------ app/helpers/application_helper.rb | 2 +- config/routes.rb | 1 - test/unit/helpers/application_helper_test.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 5edc971..7198718 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -18,12 +18,8 @@ def show def new @proposal = Proposal.new - end - - def moot - @proposal = Proposal.new - @proposal.title = URI.unescape params[:title] - render :new + title = params[:title] + @proposal.title = URI.unescape title if title end def create diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9c00466..b691645 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,7 +37,7 @@ def wikiize(text) names = {} User.all.each {|user| names[user.name] = link_to(user.name, user) } Proposal.all.each {|proposal| names[proposal.title] = link_to(proposal.title, proposal) } - text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "moot", :title => URI.escape($1)}) } + text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}) } end def markdown(text) diff --git a/config/routes.rb b/config/routes.rb index 126e730..1dfd10c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,5 @@ Vestibule::Application.routes.draw do resources :users, :only => [:show, :edit, :update] - get "/proposals/moot" resources :proposals, :except => [:destroy] do resources :suggestions, :only => [:create] member do diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index d36ce8f..5d284e0 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -41,9 +41,9 @@ class ApplicationHelperTest < ActionView::TestCase should "turn into link" do assert_equal link_to("My One and Only", "/proposals/1"), wikiize("[[My One and Only]]") - assert_equal link_to("Her Latest Idea", "/proposals/moot?title=Her%2520Latest%2520Idea"), wikiize("[[Her Latest Idea]]") + assert_equal link_to("Her Latest Idea", "/proposals/new?title=Her%2520Latest%2520Idea"), wikiize("[[Her Latest Idea]]") assert_equal( - "I prefer Her Latest Idea to My One and Only.", + "I prefer Her Latest Idea to My One and Only.", wikiize("I prefer [[Her Latest Idea]] to [[My One and Only]].") ) end From 0bcfc0e7cc38652e7a0c5c20a49d35b78cc4fb63 Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Mon, 3 Oct 2011 13:11:02 +0100 Subject: [PATCH 08/10] Links to not-yet-existent proposals black, not blue --- app/helpers/application_helper.rb | 2 +- public/stylesheets/vestibule.css | 4 +++- test/unit/helpers/application_helper_test.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b691645..d20aa4e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,7 +37,7 @@ def wikiize(text) names = {} User.all.each {|user| names[user.name] = link_to(user.name, user) } Proposal.all.each {|proposal| names[proposal.title] = link_to(proposal.title, proposal) } - text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}) } + text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}, :class => "New") } end def markdown(text) diff --git a/public/stylesheets/vestibule.css b/public/stylesheets/vestibule.css index 338ffe9..cc69e08 100644 --- a/public/stylesheets/vestibule.css +++ b/public/stylesheets/vestibule.css @@ -123,4 +123,6 @@ header .background li { #selections form, #available_selections form { float: left; -} \ No newline at end of file +} + +.New {color:black;} \ No newline at end of file diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 5d284e0..a30514f 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -41,9 +41,9 @@ class ApplicationHelperTest < ActionView::TestCase should "turn into link" do assert_equal link_to("My One and Only", "/proposals/1"), wikiize("[[My One and Only]]") - assert_equal link_to("Her Latest Idea", "/proposals/new?title=Her%2520Latest%2520Idea"), wikiize("[[Her Latest Idea]]") + assert_equal link_to("Her Latest Idea", "/proposals/new?title=Her%2520Latest%2520Idea", :class => "New"), wikiize("[[Her Latest Idea]]") assert_equal( - "I prefer Her Latest Idea to My One and Only.", + "I prefer Her Latest Idea to My One and Only.", wikiize("I prefer [[Her Latest Idea]] to [[My One and Only]].") ) end From f7541eef9a2f4afea48dd3cccf3a39b1fcb39224 Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Mon, 3 Oct 2011 14:31:50 +0100 Subject: [PATCH 09/10] @nickname links to that Vestibule user (not Twitter) --- app/helpers/application_helper.rb | 3 ++- test/unit/helpers/application_helper_test.rb | 21 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d20aa4e..df900f3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,7 +37,8 @@ def wikiize(text) names = {} User.all.each {|user| names[user.name] = link_to(user.name, user) } Proposal.all.each {|proposal| names[proposal.title] = link_to(proposal.title, proposal) } - text.gsub(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}, :class => "New") } + text.gsub!(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}, :class => "New") } + text.gsub(/(^|\W)(@(.*?))(\W|$)/) {|s| user = User.find_by_twitter_nickname $3; $1 + (user ? link_to($2, user) : $2) + $4 } end def markdown(text) diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index a30514f..f3f6058 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -27,25 +27,32 @@ class ApplicationHelperTest < ActionView::TestCase context "for a single user" do setup do @user = Factory(:user, :twitter_nickname => "rdrake98", :name => "Richard Drake") + @long = link_to("Richard Drake", "/users/rdrake98") + @short = link_to("@rdrake98", "/users/rdrake98") end should "turn into link" do - assert_equal link_to("Richard Drake", "/users/rdrake98"), wikiize("[[Richard Drake]]") + assert_equal @long, wikiize("[[Richard Drake]]") + assert_equal @short, wikiize("@rdrake98") + assert_equal "@other", wikiize("@other") + assert_equal "#{@long}same as #{@short}; #{@short} is but not @other.", wikiize("[[Richard Drake]]same as @rdrake98; @rdrake98 is but not @other.") + assert_equal "#{@long}not same as@rdrake98; #{@short} is.", wikiize("[[Richard Drake]]not same as@rdrake98; @rdrake98 is.") + # the following ain't perfect but we can probably live with it + assert_equal "#{@long}same as #{@short};@rdrake98 isn't.", wikiize("[[Richard Drake]]same as @rdrake98;@rdrake98 isn't.") end end context "for a single proposal" do setup do @user = Factory(:proposal, :title => "My One and Only") + @my_only = link_to("My One and Only", "/proposals/1") + @her_latest = link_to("Her Latest Idea", "/proposals/new?title=Her%2520Latest%2520Idea", :class => "New") end should "turn into link" do - assert_equal link_to("My One and Only", "/proposals/1"), wikiize("[[My One and Only]]") - assert_equal link_to("Her Latest Idea", "/proposals/new?title=Her%2520Latest%2520Idea", :class => "New"), wikiize("[[Her Latest Idea]]") - assert_equal( - "I prefer Her Latest Idea to My One and Only.", - wikiize("I prefer [[Her Latest Idea]] to [[My One and Only]].") - ) + assert_equal @my_only, wikiize("[[My One and Only]]") + assert_equal @her_latest, wikiize("[[Her Latest Idea]]") + assert_equal "I prefer #{@her_latest} to #{@my_only}.", wikiize("I prefer [[Her Latest Idea]] to [[My One and Only]].") end end end From db28c6fd10fd1e1ed1d40e0274b3add9cf59cc80 Mon Sep 17 00:00:00 2001 From: Richard Drake Date: Mon, 3 Oct 2011 14:57:07 +0100 Subject: [PATCH 10/10] [[]] left unchanged --- app/helpers/application_helper.rb | 4 ++-- test/unit/helpers/application_helper_test.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index df900f3..01d2d48 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,8 +37,8 @@ def wikiize(text) names = {} User.all.each {|user| names[user.name] = link_to(user.name, user) } Proposal.all.each {|proposal| names[proposal.title] = link_to(proposal.title, proposal) } - text.gsub!(/\[\[(.*?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}, :class => "New") } - text.gsub(/(^|\W)(@(.*?))(\W|$)/) {|s| user = User.find_by_twitter_nickname $3; $1 + (user ? link_to($2, user) : $2) + $4 } + text.gsub!(/\[\[(.+?)\]\]/) {|s| names[$1] || link_to($1, {:controller => "proposals", :action => "new", :title => URI.escape($1)}, :class => "New") } + text.gsub(/(^|\W)(@(.+?))(\W|$)/) {|s| user = User.find_by_twitter_nickname $3; $1 + (user ? link_to($2, user) : $2) + $4 } end def markdown(text) diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index f3f6058..72b0bfc 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -31,10 +31,15 @@ class ApplicationHelperTest < ActionView::TestCase @short = link_to("@rdrake98", "/users/rdrake98") end + should "not turn into link" do + assert_equal "[[]]", wikiize("[[]]") + # what about multiple lines inside [[...]]? + assert_equal "@other", wikiize("@other") + end + should "turn into link" do assert_equal @long, wikiize("[[Richard Drake]]") assert_equal @short, wikiize("@rdrake98") - assert_equal "@other", wikiize("@other") assert_equal "#{@long}same as #{@short}; #{@short} is but not @other.", wikiize("[[Richard Drake]]same as @rdrake98; @rdrake98 is but not @other.") assert_equal "#{@long}not same as@rdrake98; #{@short} is.", wikiize("[[Richard Drake]]not same as@rdrake98; @rdrake98 is.") # the following ain't perfect but we can probably live with it