From 2d444423e4459831bc599554292d865995b9d982 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 7 May 2013 22:09:48 +1000 Subject: [PATCH 01/17] moved member post feed to HAML --- app/views/members/show.html.haml | 2 +- app/views/members/show.rss.builder | 18 ------------------ app/views/members/show.rss.haml | 17 +++++++++++++++++ ...s.builder_spec.rb => show.rss.haml_spec.rb} | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 app/views/members/show.rss.builder create mode 100644 app/views/members/show.rss.haml rename spec/views/members/{show.rss.builder_spec.rb => show.rss.haml_spec.rb} (89%) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 297bac8c7..f84db801b 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -66,7 +66,7 @@ %div :markdown - #{g.description} + #{ strip_tags g.description } %h3 What's planted here? - g.featured_plantings.each do |p| diff --git a/app/views/members/show.rss.builder b/app/views/members/show.rss.builder deleted file mode 100644 index 69a0ebba4..000000000 --- a/app/views/members/show.rss.builder +++ /dev/null @@ -1,18 +0,0 @@ -xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do - xml.channel do - xml.title "#{Growstuff::Application.config.site_name} - #{@member.login_name}'s recent posts" - xml.link member_url(@member) - - for post in @posts - xml.item do - xml.author @member.login_name - xml.title post.subject - xml.description post.body - xml.pubDate post.created_at.to_s(:rfc822) - xml.link post_url(post) - xml.guid post_url(post) - end - end - end -end diff --git a/app/views/members/show.rss.haml b/app/views/members/show.rss.haml new file mode 100644 index 000000000..f88f44db4 --- /dev/null +++ b/app/views/members/show.rss.haml @@ -0,0 +1,17 @@ + +%feed{:version => "2.0", "xmlns:atom"=>"http://www.w3.org/2005/Atom"} + %channel + %title #{Growstuff::Application.config.site_name} - #{@member.login_name}'s recent posts + %atom:link= member_url(@member) + %atom:link{ :type => "application/rss+xml", :href => member_url(@member), :rel => "self" } + + - @posts.each do |post| + %entry + %updated post.created_at.to_s(:rfc822) + %link{ :href => post_url(post) } + %guid post_url(post) + %author @member.login_name + %title post.subject + %description + :markdown + #{ strip_tags post.body } diff --git a/spec/views/members/show.rss.builder_spec.rb b/spec/views/members/show.rss.haml_spec.rb similarity index 89% rename from spec/views/members/show.rss.builder_spec.rb rename to spec/views/members/show.rss.haml_spec.rb index 320229e3a..a9a73686a 100644 --- a/spec/views/members/show.rss.builder_spec.rb +++ b/spec/views/members/show.rss.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'members/show.rss.builder', :type => "view" do +describe 'members/show.rss.haml', :type => "view" do before(:each) do @member = assign(:member, FactoryGirl.create(:member)) assign(:posts, [ From 65431ed41f572bf13366ab4a7d6bfafe20fffcda Mon Sep 17 00:00:00 2001 From: Skud Date: Thu, 16 May 2013 21:39:17 +1000 Subject: [PATCH 02/17] some improvements to the HAML RSS --- app/views/members/show.rss.haml | 18 ++++++++--------- db/schema.rb | 35 ++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/views/members/show.rss.haml b/app/views/members/show.rss.haml index f88f44db4..85a598de8 100644 --- a/app/views/members/show.rss.haml +++ b/app/views/members/show.rss.haml @@ -1,17 +1,15 @@ -%feed{:version => "2.0", "xmlns:atom"=>"http://www.w3.org/2005/Atom"} +%rss{:version => 2.0} %channel %title #{Growstuff::Application.config.site_name} - #{@member.login_name}'s recent posts - %atom:link= member_url(@member) - %atom:link{ :type => "application/rss+xml", :href => member_url(@member), :rel => "self" } - + %link= member_url(@member) - @posts.each do |post| - %entry - %updated post.created_at.to_s(:rfc822) - %link{ :href => post_url(post) } - %guid post_url(post) - %author @member.login_name - %title post.subject + %item + %pubDate= post.created_at.to_s(:rfc822) + %link= post_url(post) + %guid= post_url(post) + %author= @member.login_name + %title= post.subject %description :markdown #{ strip_tags post.body } diff --git a/db/schema.rb b/db/schema.rb index 4c82164fe..d4bf0005f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130418102558) do +ActiveRecord::Schema.define(:version => 20130515122301) do create_table "authentications", :force => true do |t| t.integer "member_id", :null => false @@ -120,12 +120,25 @@ ActiveRecord::Schema.define(:version => 20130418102558) do t.datetime "updated_at", :null => false end - create_table "payments", :force => true do |t| - t.integer "payer_id" - t.string "payment_type" - t.decimal "amount" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "order_items", :force => true do |t| + t.integer "order_id" + t.integer "product_id" + t.integer "price" + t.integer "quantity" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "orders", :force => true do |t| + t.integer "member_id", :limit => 255, :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.datetime "completed_at" + end + + create_table "orders_products", :id => false, :force => true do |t| + t.integer "order_id" + t.integer "product_id" end create_table "plantings", :force => true do |t| @@ -155,6 +168,14 @@ ActiveRecord::Schema.define(:version => 20130418102558) do add_index "posts", ["created_at", "author_id"], :name => "index_updates_on_created_at_and_user_id" add_index "posts", ["slug"], :name => "index_updates_on_slug", :unique => true + create_table "products", :force => true do |t| + t.string "name", :null => false + t.string "description", :null => false + t.integer "min_price", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "roles", :force => true do |t| t.string "name", :null => false t.text "description" From 6b487ab1f604b690c7944bb9d1383f5c81179240 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 16 May 2013 15:08:50 +0100 Subject: [PATCH 03/17] Escaped_Markdown HAML filter, for use in RSS. I tried to do this using Haml::Filters::Markdown so it would be independent of our Markdown renderer, but I couldn't get Haml::Filters::Markdown.render to work programmatically - whatever I did, it returned its input unchanged. So I hardcoded a dependence on bluecloth. --- app/views/members/show.rss.haml | 2 +- config/initializers/escaped_markdown.rb | 1 + lib/haml/filters/escaped_markdown.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 config/initializers/escaped_markdown.rb create mode 100644 lib/haml/filters/escaped_markdown.rb diff --git a/app/views/members/show.rss.haml b/app/views/members/show.rss.haml index 85a598de8..f6244623d 100644 --- a/app/views/members/show.rss.haml +++ b/app/views/members/show.rss.haml @@ -11,5 +11,5 @@ %author= @member.login_name %title= post.subject %description - :markdown + :escaped_markdown #{ strip_tags post.body } diff --git a/config/initializers/escaped_markdown.rb b/config/initializers/escaped_markdown.rb new file mode 100644 index 000000000..87837b0c5 --- /dev/null +++ b/config/initializers/escaped_markdown.rb @@ -0,0 +1 @@ +require 'haml/filters/escaped_markdown' diff --git a/lib/haml/filters/escaped_markdown.rb b/lib/haml/filters/escaped_markdown.rb new file mode 100644 index 000000000..5c172079c --- /dev/null +++ b/lib/haml/filters/escaped_markdown.rb @@ -0,0 +1,10 @@ +gem 'bluecloth' + +module Haml::Filters::Escaped_Markdown + include Haml::Filters::Base + + def render(text) + bc = BlueCloth.new(text) + return Haml::Helpers.html_escape bc.to_html + end +end From d5c781a97ff6636556c0b24b42c28284eea02b1d Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 16 May 2013 18:00:00 +0100 Subject: [PATCH 04/17] Tests for Haml::Filters::EscapedMarkdown. --- lib/haml/filters/escaped_markdown.rb | 19 +++++++++++++------ .../lib/haml/filters/escaped_markdown_spec.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 spec/lib/haml/filters/escaped_markdown_spec.rb diff --git a/lib/haml/filters/escaped_markdown.rb b/lib/haml/filters/escaped_markdown.rb index 5c172079c..c60256ac9 100644 --- a/lib/haml/filters/escaped_markdown.rb +++ b/lib/haml/filters/escaped_markdown.rb @@ -1,10 +1,17 @@ -gem 'bluecloth' +require 'bluecloth' -module Haml::Filters::Escaped_Markdown - include Haml::Filters::Base +module Haml::Filters + module EscapedMarkdown + include Haml::Filters::Base - def render(text) - bc = BlueCloth.new(text) - return Haml::Helpers.html_escape bc.to_html + def render(text) + bc = BlueCloth.new(text) + return Haml::Helpers.html_escape bc.to_html + end end + +# Register it as the handler for the :escaped_markdown HAML command. +# The automatic system gives us :escapedmarkdown, which is ugly. +defined['escaped_markdown'] = EscapedMarkdown + end diff --git a/spec/lib/haml/filters/escaped_markdown_spec.rb b/spec/lib/haml/filters/escaped_markdown_spec.rb new file mode 100644 index 000000000..99c779e88 --- /dev/null +++ b/spec/lib/haml/filters/escaped_markdown_spec.rb @@ -0,0 +1,16 @@ +require 'haml/filters' +require 'haml/filters/escaped_markdown' +require 'haml/helpers' + +describe 'Haml::Filters::Escaped_Markdown' do + it 'is registered as the handler for :escaped_markdown' do + Haml::Filters::defined['escaped_markdown'].should == + Haml::Filters::EscapedMarkdown + end + + it 'converts Markdown to escaped HTML' do + rendered = Haml::Filters::EscapedMarkdown.render("**foo**") + rendered.should == "<p><strong>foo</strong></p>" + end + +end From 2d3b594ae160f80786d54de1af7c0e2348c8a444 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 16 May 2013 18:24:22 +0100 Subject: [PATCH 05/17] Test for expanded-markdown rendering. --- spec/views/members/show.rss.haml_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/views/members/show.rss.haml_spec.rb b/spec/views/members/show.rss.haml_spec.rb index a9a73686a..adb6e0bc3 100644 --- a/spec/views/members/show.rss.haml_spec.rb +++ b/spec/views/members/show.rss.haml_spec.rb @@ -5,7 +5,7 @@ describe 'members/show.rss.haml', :type => "view" do @member = assign(:member, FactoryGirl.create(:member)) assign(:posts, [ FactoryGirl.build(:post, :id => 1, :author => @member), - FactoryGirl.build(:post, :id => 2, :author => @member) + FactoryGirl.build(:markdown_post, :id => 2, :author => @member) ]) render end @@ -18,4 +18,10 @@ describe 'members/show.rss.haml', :type => "view" do rendered.should contain "This is some text." end + it 'renders post bodies to HTML and XML-escapes them' do +# The variable "rendered" has been entity-replaced and tag-stripped +# The literal string output contains "<strong>" etc. + rendered.should contain "strong" + end + end From e588b312f9a3850a6eac32237f11918ed575f0c6 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 20 May 2013 14:56:53 +1000 Subject: [PATCH 06/17] Added list of contributors I know git(hub) gives us much of this, but it doesn't credit the "copilot" from pairing, so this is a way to list *everyone* who's contributed to our code, even if they didn't do the actual commit with their own github account. --- CONTRIBUTORS.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CONTRIBUTORS.md diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 000000000..176cbf63d --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,33 @@ +This is a list of contributors to Growstuff's codebase. We maintain +this list because we work in pairs, but Github only knows about the +person who actually does the commits. This gives credit to both members +of the pair. + +If you contribute, please add yourself to the bottom of the list and +submit the change with your pull request. + +- Alex Bayley / [Skud](https://github.com/Skud) +- Ricky Amianym / [amianym](https://github.com/amianym) +- Cesy / [cesy](https://github.com/cesy) +- Miles Gould / [pozorvlak](https://github.com/pozorvlak) +- Juliet Kemp / [julietk](https://github.com/julietk) +- Federico Mena Quintero / [federicomenaquintero](https://github.com/federicomenaquintero) +- Jay Springett / [thejaymo](https://github.com/thejaymo) +- Maia Sauren / [sauramaia](https://github.com/sauramaia) +- Joseph Caudle / [jcaudle](https://github.com/jcaudle) +- Norman Ancajas / [nbancajas](https://github.com/nbancajas) +- Jonathan "Duke" Leto / [leto](https://github.com/leto) +- Mackenzie Morgan / [maco](https://github.com/maco) +- Amy Hendrix / [sabreuse](https://github.com/sabreuse) +- CephLPod / [cephLpod](https://github.com/cephLpod/) +- Gemma Mason / [gemmaellen](https://github.com/gemmaellen) +- Courtney Webster / [phazel](https://github.com/phazel/) +- Cathy Sullivan / [cesullivan](https://github.com/cesullivan) +- Jared McCorkindale / [jmcorkindale](https://github.com/jmcorkindale) +- Florian Vallen / [flov](https://github.com/flov) +- Samuel Cochrane / [sj26](https://github.com/sj26) +- Ju Transcendancing / [transcendancing](https://github.com/transcendancing) +- Lillian Ryan / [attlebish](https://github.com/attlebish) +- Gary Traffanstedt / [blimey85](https://github.com/blimey85) +- Yaw Boakye [yawboakye](https://github.com/yawboakye) +- Ryan Clark / [IAMRYO](https://github.com/IAMRYO) From 1ad27fc8851ce2a2a400791c8a4cc22b1db077a1 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 20 May 2013 15:00:29 +1000 Subject: [PATCH 07/17] Broke out "committers" and "contributors" I figured this would make it easier to show who's a good person to ask for help or information, while still crediting everyone who's contributed. --- CONTRIBUTORS.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 176cbf63d..9f8a3c74a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,15 +6,20 @@ of the pair. If you contribute, please add yourself to the bottom of the list and submit the change with your pull request. +## Committers + - Alex Bayley / [Skud](https://github.com/Skud) -- Ricky Amianym / [amianym](https://github.com/amianym) - Cesy / [cesy](https://github.com/cesy) - Miles Gould / [pozorvlak](https://github.com/pozorvlak) +- Joseph Caudle / [jcaudle](https://github.com/jcaudle) + +## Contributors + +- Ricky Amianym / [amianym](https://github.com/amianym) - Juliet Kemp / [julietk](https://github.com/julietk) - Federico Mena Quintero / [federicomenaquintero](https://github.com/federicomenaquintero) - Jay Springett / [thejaymo](https://github.com/thejaymo) - Maia Sauren / [sauramaia](https://github.com/sauramaia) -- Joseph Caudle / [jcaudle](https://github.com/jcaudle) - Norman Ancajas / [nbancajas](https://github.com/nbancajas) - Jonathan "Duke" Leto / [leto](https://github.com/leto) - Mackenzie Morgan / [maco](https://github.com/maco) @@ -29,5 +34,5 @@ submit the change with your pull request. - Ju Transcendancing / [transcendancing](https://github.com/transcendancing) - Lillian Ryan / [attlebish](https://github.com/attlebish) - Gary Traffanstedt / [blimey85](https://github.com/blimey85) -- Yaw Boakye [yawboakye](https://github.com/yawboakye) +- Yaw Boakye / [yawboakye](https://github.com/yawboakye) - Ryan Clark / [IAMRYO](https://github.com/IAMRYO) From bc03a5c488650e9c49a8d34f6e6a045daf80266d Mon Sep 17 00:00:00 2001 From: Craig Read Date: Fri, 24 May 2013 11:58:40 +1000 Subject: [PATCH 08/17] Converted Posts RSS to HAML --- app/views/posts/index.rss.builder | 18 -------- app/views/posts/index.rss.haml | 15 +++++++ db/schema.rb | 41 ++++++------------- ...builder_spec.rb => index.rss.haml_spec.rb} | 2 +- 4 files changed, 29 insertions(+), 47 deletions(-) delete mode 100644 app/views/posts/index.rss.builder create mode 100644 app/views/posts/index.rss.haml rename spec/views/posts/{index.rss.builder_spec.rb => index.rss.haml_spec.rb} (89%) diff --git a/app/views/posts/index.rss.builder b/app/views/posts/index.rss.builder deleted file mode 100644 index 88025252c..000000000 --- a/app/views/posts/index.rss.builder +++ /dev/null @@ -1,18 +0,0 @@ -xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do - xml.channel do - xml.title "#{Growstuff::Application.config.site_name} - Recent posts from all members" - xml.link posts_url - - for post in @recent_posts - xml.item do - xml.author post.author.login_name - xml.title post.subject - xml.description post.body - xml.pubDate post.created_at.to_s(:rfc822) - xml.link post_url(post) - xml.guid post_url(post) - end - end - end -end diff --git a/app/views/posts/index.rss.haml b/app/views/posts/index.rss.haml new file mode 100644 index 000000000..d54ea83da --- /dev/null +++ b/app/views/posts/index.rss.haml @@ -0,0 +1,15 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recent posts from all members + %link= posts_url + - @recent_posts.each do |post| + %item + %author= post.author.login_name + %title= post.subject + %description + :escaped_markdown + #{ strip_tags post.body } + %pubDate= post.created_at.to_s(:rfc822) + %link= post_url(post) + %guid= post_url(post) diff --git a/db/schema.rb b/db/schema.rb index d4bf0005f..c26161002 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130515122301) do +ActiveRecord::Schema.define(:version => 20130409162140) do create_table "authentications", :force => true do |t| t.integer "member_id", :null => false @@ -95,6 +95,11 @@ ActiveRecord::Schema.define(:version => 20130515122301) do t.string "location" t.float "latitude" t.float "longitude" + t.text "about_me" + t.string "full_name" + t.string "gardening_since" + t.string "wish_i_could_grow" + t.string "gardening_clothes" t.boolean "send_notification_email", :default => true end @@ -120,25 +125,13 @@ ActiveRecord::Schema.define(:version => 20130515122301) do t.datetime "updated_at", :null => false end - create_table "order_items", :force => true do |t| - t.integer "order_id" - t.integer "product_id" - t.integer "price" - t.integer "quantity" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "orders", :force => true do |t| - t.integer "member_id", :limit => 255, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.datetime "completed_at" - end - - create_table "orders_products", :id => false, :force => true do |t| - t.integer "order_id" - t.integer "product_id" + create_table "payments", :force => true do |t| + t.integer "payer_id" + t.decimal "amount" + t.date "paid_period_begins" + t.date "paid_period_ends" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "plantings", :force => true do |t| @@ -168,14 +161,6 @@ ActiveRecord::Schema.define(:version => 20130515122301) do add_index "posts", ["created_at", "author_id"], :name => "index_updates_on_created_at_and_user_id" add_index "posts", ["slug"], :name => "index_updates_on_slug", :unique => true - create_table "products", :force => true do |t| - t.string "name", :null => false - t.string "description", :null => false - t.integer "min_price", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "roles", :force => true do |t| t.string "name", :null => false t.text "description" diff --git a/spec/views/posts/index.rss.builder_spec.rb b/spec/views/posts/index.rss.haml_spec.rb similarity index 89% rename from spec/views/posts/index.rss.builder_spec.rb rename to spec/views/posts/index.rss.haml_spec.rb index f2b6c87e4..b839cf945 100644 --- a/spec/views/posts/index.rss.builder_spec.rb +++ b/spec/views/posts/index.rss.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'posts/index.rss.builder', :type => "view" do +describe 'posts/index.rss.haml', :type => "view" do before(:each) do controller.stub(:current_user) { nil } @author = FactoryGirl.create(:member) From 9c2fed461ddd4415543063fe9c08d080b95b0d2b Mon Sep 17 00:00:00 2001 From: Craig Read Date: Fri, 24 May 2013 12:05:47 +1000 Subject: [PATCH 09/17] Removed redundant @recent_posts instance variable Not required, as we have pagination by default --- app/controllers/posts_controller.rb | 1 - app/views/posts/index.rss.haml | 2 +- spec/controllers/posts_controller_spec.rb | 1 - spec/views/posts/index.rss.haml_spec.rb | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1ca2b5f94..6bec61061 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -5,7 +5,6 @@ class PostsController < ApplicationController def index @posts = Post.paginate(:page => params[:page]) - @recent_posts = Post.limit(100).order('created_at desc').all respond_to do |format| format.html # index.html.haml diff --git a/app/views/posts/index.rss.haml b/app/views/posts/index.rss.haml index d54ea83da..12402d0cf 100644 --- a/app/views/posts/index.rss.haml +++ b/app/views/posts/index.rss.haml @@ -3,7 +3,7 @@ %channel %title #{Growstuff::Application.config.site_name} - Recent posts from all members %link= posts_url - - @recent_posts.each do |post| + - @posts.each do |post| %item %author= post.author.login_name %title= post.subject diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5fe9c1ddd..f87f90fb9 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -13,7 +13,6 @@ describe PostsController do post = Post.create! valid_attributes get :index, {} assigns(:posts).should eq([post]) - assigns(:recent_posts).should eq([post]) end end diff --git a/spec/views/posts/index.rss.haml_spec.rb b/spec/views/posts/index.rss.haml_spec.rb index b839cf945..cd5f74c4d 100644 --- a/spec/views/posts/index.rss.haml_spec.rb +++ b/spec/views/posts/index.rss.haml_spec.rb @@ -4,7 +4,7 @@ describe 'posts/index.rss.haml', :type => "view" do before(:each) do controller.stub(:current_user) { nil } @author = FactoryGirl.create(:member) - assign(:recent_posts, [ + assign(:posts, [ FactoryGirl.build(:post, :id => 1, :author => @author), FactoryGirl.build(:post, :id => 2, :author => @author) ]) From d563f0ceae71185b72cff5a061b46fceb9f0e750 Mon Sep 17 00:00:00 2001 From: Craig Read Date: Fri, 24 May 2013 12:22:41 +1000 Subject: [PATCH 10/17] Converting crops RSS to HAML Added spec for crops RSS Removed redundant @new_crops instance variable (not needed as we now have pagination). --- app/controllers/crops_controller.rb | 1 - app/views/crops/index.rss.builder | 16 ---------------- app/views/crops/index.rss.haml | 11 +++++++++++ spec/controllers/crops_controller_spec.rb | 1 - spec/views/crops/index.rss.haml_spec.rb | 23 +++++++++++++++++++++++ 5 files changed, 34 insertions(+), 18 deletions(-) delete mode 100644 app/views/crops/index.rss.builder create mode 100644 app/views/crops/index.rss.haml create mode 100644 spec/views/crops/index.rss.haml_spec.rb diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index f0cfe2525..26a3de663 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -5,7 +5,6 @@ class CropsController < ApplicationController # GET /crops.json def index @crops = Crop.paginate(:page => params[:page]) - @new_crops = Crop.limit(20).order('created_at desc').all respond_to do |format| format.html # index.html.haml diff --git a/app/views/crops/index.rss.builder b/app/views/crops/index.rss.builder deleted file mode 100644 index 9410a6080..000000000 --- a/app/views/crops/index.rss.builder +++ /dev/null @@ -1,16 +0,0 @@ -xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do - xml.channel do - xml.title "#{Growstuff::Application.config.site_name} - Recently added crops" - xml.link crops_url - - for crop in @new_crops - xml.item do - xml.title crop.system_name - xml.pubDate crop.created_at.to_s(:rfc822) - xml.link crop_url(crop) - xml.guid crop_url(crop) - end - end - end -end diff --git a/app/views/crops/index.rss.haml b/app/views/crops/index.rss.haml new file mode 100644 index 000000000..1fd02870e --- /dev/null +++ b/app/views/crops/index.rss.haml @@ -0,0 +1,11 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recently added crops + %link= crops_url + - @crops.each do |crop| + %item + %title= crop.system_name + %pubDate= crop.created_at.to_s(:rfc822) + %link= post_url(crop) + %guid= post_url(crop) \ No newline at end of file diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index db4c070bc..f56c7ee3b 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -16,7 +16,6 @@ describe CropsController do crop = Crop.create! valid_attributes get :index, {} assigns(:crops).should eq([crop]) - assigns(:new_crops).should eq([crop]) end end diff --git a/spec/views/crops/index.rss.haml_spec.rb b/spec/views/crops/index.rss.haml_spec.rb new file mode 100644 index 000000000..8790a7d80 --- /dev/null +++ b/spec/views/crops/index.rss.haml_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'crops/index.rss.haml' do + before(:each) do + controller.stub(:current_user) { nil } + @author = FactoryGirl.create(:member) + assign(:crops, [ + FactoryGirl.create(:tomato), + FactoryGirl.create(:maize) + ]) + render + end + + it 'shows RSS feed title' do + rendered.should contain "Recently added crops" + end + + it 'shows names of crops' do + rendered.should contain "Tomato" + rendered.should contain "Maize" + end + +end From 9437e6576340d83c1238bf76dfe1616d4f0c87fe Mon Sep 17 00:00:00 2001 From: Craig Read Date: Fri, 24 May 2013 12:35:08 +1000 Subject: [PATCH 11/17] Replaced plantings RSS with HAML Removed the redundant @recent_plantings variable and added pagination --- app/controllers/plantings_controller.rb | 3 +- app/views/plantings/index.html.haml | 10 +++++-- app/views/plantings/index.rss.builder | 18 ----------- app/views/plantings/index.rss.haml | 15 ++++++++++ spec/controllers/plantings_controller_spec.rb | 1 - spec/views/plantings/index.html.haml_spec.rb | 30 +++++++++++-------- ...builder_spec.rb => index.rss.haml_spec.rb} | 8 ++--- 7 files changed, 46 insertions(+), 39 deletions(-) delete mode 100644 app/views/plantings/index.rss.builder create mode 100644 app/views/plantings/index.rss.haml rename spec/views/plantings/{index.rss.builder_spec.rb => index.rss.haml_spec.rb} (58%) diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index ff9ebe886..7a7c61119 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -3,8 +3,7 @@ class PlantingsController < ApplicationController # GET /plantings # GET /plantings.json def index - @plantings = Planting.all - @recent_plantings = Planting.limit(100).order('created_at desc').all + @plantings = Planting.paginate(:page => params[:page]) respond_to do |format| format.html # index.html.erb diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index d359a342d..fd628410d 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -2,7 +2,13 @@ %p Here are the latest things planted by #{Growstuff::Application.config.site_name} members. -- @recent_plantings.each do |p| +%div.pagination + = page_entries_info @plantings, :model => "plantings" + = will_paginate @plantings + +- @plantings.each do |p| = render :partial => "plantings/thumbnail", :locals => { :planting => p } - +%div.pagination + = page_entries_info @plantings, :model => "plantings" + = will_paginate @plantings \ No newline at end of file diff --git a/app/views/plantings/index.rss.builder b/app/views/plantings/index.rss.builder deleted file mode 100644 index f203ca488..000000000 --- a/app/views/plantings/index.rss.builder +++ /dev/null @@ -1,18 +0,0 @@ -xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do - xml.channel do - xml.title "#{Growstuff::Application.config.site_name} - Recent plantings from all members" - xml.link plantings_url - - for planting in @recent_plantings - xml.item do - xml.author planting.owner.login_name - xml.title planting.crop.system_name - xml.pubDate planting.created_at.to_s(:rfc822) - xml.description planting.description - xml.link planting_url(planting) - xml.guid planting_url(planting) - end - end - end -end diff --git a/app/views/plantings/index.rss.haml b/app/views/plantings/index.rss.haml new file mode 100644 index 000000000..d6ed95542 --- /dev/null +++ b/app/views/plantings/index.rss.haml @@ -0,0 +1,15 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recent plantings from all members + %link= plantings_url + - @plantings.each do |planting| + %item + %author= planting.owner.login_name + %title= planting.crop.system_name + %pubDate= planting.created_at.to_s(:rfc822) + %description + :escaped_markdown + #{ strip_tags planting.description } + %link= planting_url(planting) + %guid= planting_url(planting) diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index ff3fc9e36..fec82c7e8 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -16,7 +16,6 @@ describe PlantingsController do planting = Planting.create! valid_attributes get :index, {} assigns(:plantings).should eq([planting]) - assigns(:recent_plantings).should eq([planting]) end end diff --git a/spec/views/plantings/index.html.haml_spec.rb b/spec/views/plantings/index.html.haml_spec.rb index cb7cec5a5..16339f665 100644 --- a/spec/views/plantings/index.html.haml_spec.rb +++ b/spec/views/plantings/index.html.haml_spec.rb @@ -7,18 +7,24 @@ describe "plantings/index" do @garden = FactoryGirl.create(:garden, :owner => @member) @tomato = FactoryGirl.create(:tomato) @maize = FactoryGirl.create(:maize) - assign(:recent_plantings, [ - FactoryGirl.create(:planting, - :garden => @garden, - :crop => @tomato - ), - FactoryGirl.create(:planting, - :garden => @garden, - :crop => @maize, - :description => '', - :planted_at => Time.local(2013, 1, 13) - ) - ]) + page = 1 + per_page = 2 + total_entries = 2 + plantings = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + pager.replace([ + FactoryGirl.create(:planting, + :garden => @garden, + :crop => @tomato + ), + FactoryGirl.create(:planting, + :garden => @garden, + :crop => @maize, + :description => '', + :planted_at => Time.local(2013, 1, 13) + ) + ]) + end + assign(:plantings, plantings) render end diff --git a/spec/views/plantings/index.rss.builder_spec.rb b/spec/views/plantings/index.rss.haml_spec.rb similarity index 58% rename from spec/views/plantings/index.rss.builder_spec.rb rename to spec/views/plantings/index.rss.haml_spec.rb index abc847d45..a689707fc 100644 --- a/spec/views/plantings/index.rss.builder_spec.rb +++ b/spec/views/plantings/index.rss.haml_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe 'plantings/index.rss.builder', :type => "view" do +describe 'plantings/index.rss.haml' do before(:each) do controller.stub(:current_user) { nil } - assign(:recent_plantings, [ + assign(:plantings, [ FactoryGirl.create(:planting) ]) render @@ -13,8 +13,8 @@ describe 'plantings/index.rss.builder', :type => "view" do rendered.should contain "Recent plantings from all members" end - it 'shows content of posts' do - rendered.should contain "This is a *really* good plant." + it 'shows formatted content of posts' do + rendered.should contain "This is a really good plant." end end From 57f8575ab9316793ec1f7307e5bd437ab4386610 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 24 May 2013 12:54:57 +1000 Subject: [PATCH 12/17] removed unwanted @recent_comments, replaced w pagination --- .gitignore | 4 +++- app/controllers/comments_controller.rb | 3 +-- app/views/comments/index.html.haml | 10 +++++++++- app/views/plantings/index.html.haml | 2 +- spec/controllers/comments_controller_spec.rb | 1 - spec/views/comments/index.html.haml_spec.rb | 15 +++++++++++---- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5b8787714..9b5a1cf4b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ *~ *.DS_Store credentials.sh -Pathogen: \ No newline at end of file +Pathogen: +custom_plan.rb +zeus.json diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d6bc30bd1..969385361 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -2,8 +2,7 @@ class CommentsController < ApplicationController # GET /comments # GET /comments.json def index - @comments = Comment.all - @recent_comments = Comment.limit(100).order('created_at desc').all + @comments = Comment.paginate(:page => params[:page]) respond_to do |format| format.html # index.html.erb diff --git a/app/views/comments/index.html.haml b/app/views/comments/index.html.haml index a6a95d2d9..64915fc3c 100644 --- a/app/views/comments/index.html.haml +++ b/app/views/comments/index.html.haml @@ -1,7 +1,15 @@ = content_for :title, "Recent comments" -- @recent_comments.each do |comment| +%div.pagination + = page_entries_info @comments, :model => "comments" + = will_paginate @comments + +- @comments.each do |comment| %h2 Comment on = link_to comment.post.subject, comment.post = render :partial => "single", :locals => { :comment => comment } + +%div.pagination + = page_entries_info @comments, :model => "comments" + = will_paginate @comments diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index fd628410d..6e98960ad 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -11,4 +11,4 @@ %div.pagination = page_entries_info @plantings, :model => "plantings" - = will_paginate @plantings \ No newline at end of file + = will_paginate @plantings diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 587d24407..ec76ec799 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -14,7 +14,6 @@ describe CommentsController do comment = Comment.create! valid_attributes get :index, {} assigns(:comments).should eq([comment]) - assigns(:recent_comments).should eq([comment]) end end diff --git a/spec/views/comments/index.html.haml_spec.rb b/spec/views/comments/index.html.haml_spec.rb index f2633c648..dac2dcc5b 100644 --- a/spec/views/comments/index.html.haml_spec.rb +++ b/spec/views/comments/index.html.haml_spec.rb @@ -3,10 +3,17 @@ require 'spec_helper' describe "comments/index" do before(:each) do controller.stub(:current_user) { nil } - assign(:recent_comments, [ - FactoryGirl.create(:comment), - FactoryGirl.create(:comment, :body => 'ROFL') - ]) + page = 1 + per_page = 2 + total_entries = 2 + comments = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + pager.replace([ + FactoryGirl.create(:comment), + FactoryGirl.create(:comment, :body => 'ROFL') + ]) + end + assign(:comments, comments) + render end it "renders a list of comments" do From 0d3588535ef0539fe9ddb3d890abe3f9b0c14a22 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 24 May 2013 13:29:17 +1000 Subject: [PATCH 13/17] Added RSS feed for all comments --- app/controllers/comments_controller.rb | 1 + app/views/comments/index.rss.haml | 22 +++++++++++++++ app/views/crops/index.rss.haml | 2 +- spec/controllers/comments_controller_spec.rb | 9 +++++++ spec/views/comments/index.rss.haml_spec.rb | 28 ++++++++++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/views/comments/index.rss.haml create mode 100644 spec/views/comments/index.rss.haml_spec.rb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 969385361..c14b0123b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -7,6 +7,7 @@ class CommentsController < ApplicationController respond_to do |format| format.html # index.html.erb format.json { render json: @comments } + format.rss { render :layout => false } end end diff --git a/app/views/comments/index.rss.haml b/app/views/comments/index.rss.haml new file mode 100644 index 000000000..7408684f9 --- /dev/null +++ b/app/views/comments/index.rss.haml @@ -0,0 +1,22 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recent comments on all posts + %link= comments_url + - @comments.each do |comment| + %item + %author= comment.author.login_name + %description + + :escaped +

+ Comment on + #{ link_to comment.post.subject, post_url(comment.post) } +

+ + :escaped_markdown + #{ strip_tags comment.body } + + %pubDate= comment.created_at.to_s(:rfc822) + %link= post_url(comment.post) + %guid= post_url(comment.post) diff --git a/app/views/crops/index.rss.haml b/app/views/crops/index.rss.haml index 1fd02870e..aabd178ac 100644 --- a/app/views/crops/index.rss.haml +++ b/app/views/crops/index.rss.haml @@ -8,4 +8,4 @@ %title= crop.system_name %pubDate= crop.created_at.to_s(:rfc822) %link= post_url(crop) - %guid= post_url(crop) \ No newline at end of file + %guid= post_url(crop) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index ec76ec799..f247fc78f 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -17,6 +17,15 @@ describe CommentsController do end end + describe "GET RSS feed" do + it "returns an RSS feed" do + get :index, :format => "rss" + response.should be_success + response.should render_template("comments/index") + response.content_type.should eq("application/rss+xml") + end + end + describe "GET show" do it "assigns the requested comment as @comment" do comment = Comment.create! valid_attributes diff --git a/spec/views/comments/index.rss.haml_spec.rb b/spec/views/comments/index.rss.haml_spec.rb new file mode 100644 index 000000000..73bf99b99 --- /dev/null +++ b/spec/views/comments/index.rss.haml_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe 'comments/index.rss.haml' do + before(:each) do + controller.stub(:current_user) { nil } + @author = FactoryGirl.create(:member) + @post = FactoryGirl.create(:post) + assign(:comments, [ + FactoryGirl.create(:comment, :author => @author, :post => @post), + FactoryGirl.create(:comment, :author => @author, :post => @post) + ]) + render + end + + it 'shows RSS feed title' do + rendered.should contain "Recent comments on all posts" + end + + it 'escapes html for link to post' do + # it's then unescaped by 'render' so we don't actually look for < + rendered.should contain ' Date: Fri, 24 May 2013 13:43:06 +1000 Subject: [PATCH 14/17] Added RSS feed for comments on a single post --- app/controllers/posts_controller.rb | 4 ++++ app/views/posts/show.rss.haml | 22 ++++++++++++++++++ spec/controllers/posts_controller_spec.rb | 10 +++++++++ spec/views/posts/show.rss.haml_spec.rb | 27 +++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 app/views/posts/show.rss.haml create mode 100644 spec/views/posts/show.rss.haml_spec.rb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 6bec61061..de7c80091 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -22,6 +22,10 @@ class PostsController < ApplicationController respond_to do |format| format.html # show.html.haml format.json { render json: @post } + format.rss { render( + :layout => false, + :locals => { :post => @post } + )} end end diff --git a/app/views/posts/show.rss.haml b/app/views/posts/show.rss.haml new file mode 100644 index 000000000..2b4362225 --- /dev/null +++ b/app/views/posts/show.rss.haml @@ -0,0 +1,22 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recent comments on #{@post.subject} + %link= post_url(@post) + - @post.comments.each do |comment| + %item + %author= comment.author.login_name + %description + + :escaped +

+ Comment on + #{ link_to @post.subject, post_url(@post) } +

+ + :escaped_markdown + #{ strip_tags comment.body } + + %pubDate= comment.created_at.to_s(:rfc822) + %link= post_url(@post) + %guid= post_url(@post) diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index f87f90fb9..bdae1ce48 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -33,6 +33,16 @@ describe PostsController do end end + describe "GET RSS feed for individual post" do + it "returns an RSS feed" do + post = Post.create! valid_attributes + get :show, { :format => "rss", :id => post.slug } + response.should be_success + response.should render_template("posts/show") + response.content_type.should eq("application/rss+xml") + end + end + describe "GET new" do it "assigns a new post as @post" do get :new, {} diff --git a/spec/views/posts/show.rss.haml_spec.rb b/spec/views/posts/show.rss.haml_spec.rb new file mode 100644 index 000000000..cfcf380e3 --- /dev/null +++ b/spec/views/posts/show.rss.haml_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe 'posts/show.rss.haml' do + before(:each) do + controller.stub(:current_user) { nil } + @author = FactoryGirl.create(:member) + @post = FactoryGirl.create(:post) + FactoryGirl.create(:comment, :author => @author, :post => @post) + FactoryGirl.create(:comment, :author => @author, :post => @post) + assign(:post, @post) + render + end + + it 'shows RSS feed title' do + rendered.should contain "Recent comments on #{@post.subject}" + end + + it 'escapes html for link to post' do + # it's then unescaped by 'render' so we don't actually look for < + rendered.should contain '
Date: Fri, 24 May 2013 14:36:58 +1000 Subject: [PATCH 15/17] Reordered comments: they are now DESC by default Added scope "post_order" to order them ASC for display on post page. Also tweaked post/comment views a bit. --- app/models/comment.rb | 3 +- app/views/comments/_form.html.haml | 5 -- app/views/comments/edit.html.haml | 4 + app/views/comments/new.html.haml | 6 ++ app/views/posts/_comments.html.haml | 6 +- spec/controllers/comments_controller_spec.rb | 2 +- spec/models/comment_spec.rb | 81 +++++++++++++------- spec/views/comments/new.html.haml_spec.rb | 8 +- 8 files changed, 73 insertions(+), 42 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index ea2082bf9..f797848e0 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,7 +3,8 @@ class Comment < ActiveRecord::Base belongs_to :author, :class_name => 'Member' belongs_to :post - default_scope order("created_at asc") + default_scope order("created_at DESC") + scope :post_order, reorder("created_at ASC") # for display on post page after_create do recipient = self.post.author.id diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml index 06b6d0f8b..3e3f6f66b 100644 --- a/app/views/comments/_form.html.haml +++ b/app/views/comments/_form.html.haml @@ -1,8 +1,3 @@ -= render :partial => "posts/single", :locals => { :post => @post || @comment.post, :subject => true } - -= render :partial => "posts/comments" - -%h2 Your comment = form_for @comment do |f| - if @comment.errors.any? #error_explanation diff --git a/app/views/comments/edit.html.haml b/app/views/comments/edit.html.haml index 7b07b546d..912c8a8b8 100644 --- a/app/views/comments/edit.html.haml +++ b/app/views/comments/edit.html.haml @@ -1,3 +1,7 @@ = content_for :title, "Editing comment" +%p + Editing comment on + = link_to @comment.post.subject, @comment.post + = render 'form' diff --git a/app/views/comments/new.html.haml b/app/views/comments/new.html.haml index 66393a209..c01ee755f 100644 --- a/app/views/comments/new.html.haml +++ b/app/views/comments/new.html.haml @@ -1,3 +1,9 @@ = content_for :title, "New comment" += render :partial => "posts/single", :locals => { :post => @post || @comment.post, :subject => true } + += render :partial => "posts/comments", :locals => {:post => @post || @comment.post} + +%p Your comment: + = render 'form' diff --git a/app/views/posts/_comments.html.haml b/app/views/posts/_comments.html.haml index c06124014..bf565debc 100644 --- a/app/views/posts/_comments.html.haml +++ b/app/views/posts/_comments.html.haml @@ -1,8 +1,8 @@ %a{:name => "comments"} -- if @comments +- if post.comments %h2 - =pluralize(@comments.length, "comment") - - @comments.each do |c| + =pluralize(post.comments.length, "comment") + - post.comments.post_order.each do |c| = render :partial => "comments/single", :locals => { :comment => c } - else diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index f247fc78f..128bcdd4e 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -71,7 +71,7 @@ describe CommentsController do old_comment = FactoryGirl.create(:comment, :post => post) comment = FactoryGirl.create(:comment, :post => post) get :edit, {:id => comment.to_param} - assigns(:comments).should eq([old_comment, comment]) + assigns(:comments).should eq([comment, old_comment]) end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 7bad161bf..d487d0b91 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -2,40 +2,65 @@ require 'spec_helper' describe Comment do - before(:each) do - @comment = FactoryGirl.create(:comment) + context "basic" do + before(:each) do + @comment = FactoryGirl.create(:comment) + end + + it "belongs to a post" do + @comment.post.should be_an_instance_of Post + end + + it "belongs to an author" do + @comment.author.should be_an_instance_of Member + end end - it "belongs to a post" do - @comment.post.should be_an_instance_of Post + context "notifications" do + before(:each) do + @comment = FactoryGirl.create(:comment) + end + + it "sends a notification when a comment is posted" do + expect { + FactoryGirl.create(:comment) + }.to change(Notification, :count).by(1) + end + + it "sets the notification fields" do + @c = FactoryGirl.create(:comment) + @n = Notification.first + @n.sender.should eq @c.author + @n.recipient.should eq @c.post.author + @n.subject.should match /commented on/ + @n.body.should eq @c.body + @n.post.should eq @c.post + end + + it "doesn't send notifications to yourself" do + @m = FactoryGirl.create(:member) + @p = FactoryGirl.create(:post, :author => @m) + expect { + FactoryGirl.create(:comment, :post => @p, :author => @m) + }.to change(Notification, :count).by(0) + end end - it "belongs to an author" do - @comment.author.should be_an_instance_of Member - end + context "ordering" do + before(:each) do + @m = FactoryGirl.create(:member) + @p = FactoryGirl.create(:post, :author => @m) + @c1 = FactoryGirl.create(:comment, :post => @p, :author => @m) + @c2 = FactoryGirl.create(:comment, :post => @p, :author => @m) + end - it "sends a notification when a comment is posted" do - expect { - FactoryGirl.create(:comment) - }.to change(Notification, :count).by(1) - end + it 'is in DESC order by default' do + Comment.all.should eq [@c2, @c1] + end - it "sets the notification fields" do - @c = FactoryGirl.create(:comment) - @n = Notification.first - @n.sender.should eq @c.author - @n.recipient.should eq @c.post.author - @n.subject.should match /commented on/ - @n.body.should eq @c.body - @n.post.should eq @c.post - end - - it "doesn't send notifications to yourself" do - @m = FactoryGirl.create(:member) - @p = FactoryGirl.create(:post, :author => @m) - expect { - FactoryGirl.create(:comment, :post => @p, :author => @m) - }.to change(Notification, :count).by(0) + it 'has a scope for ASC order for displaying on post page' do + Comment.post_order.should eq [@c1, @c2] + end end end diff --git a/spec/views/comments/new.html.haml_spec.rb b/spec/views/comments/new.html.haml_spec.rb index 90b5e1cb3..a27868a16 100644 --- a/spec/views/comments/new.html.haml_spec.rb +++ b/spec/views/comments/new.html.haml_spec.rb @@ -4,9 +4,9 @@ describe "comments/new" do before(:each) do controller.stub(:current_user) { nil } @post = FactoryGirl.create(:post) - @previous_comment = FactoryGirl.create(:comment, :post => @post) - assign(:comment, FactoryGirl.create(:comment, :post => @post)) - assign(:comments, [@previous_comment]) + @comment = FactoryGirl.create(:comment, :post => @post) + assign(:comment, @comment) + assign(:comments, [@comment]) render end @@ -15,7 +15,7 @@ describe "comments/new" do end it "shows previous comments" do - rendered.should contain @previous_comment.body + rendered.should contain @comment.body end it "shows the correct comment count" do From 18b92b133b95c3c35b406de44853f77c4fde4251 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 24 May 2013 14:43:45 +1000 Subject: [PATCH 16/17] Added titles to comment items in RSS --- app/views/comments/index.rss.haml | 1 + app/views/posts/show.rss.haml | 1 + spec/views/comments/index.rss.haml_spec.rb | 4 ++++ spec/views/posts/show.rss.haml_spec.rb | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/app/views/comments/index.rss.haml b/app/views/comments/index.rss.haml index 7408684f9..5e4b227c5 100644 --- a/app/views/comments/index.rss.haml +++ b/app/views/comments/index.rss.haml @@ -5,6 +5,7 @@ %link= comments_url - @comments.each do |comment| %item + %title Comment by #{comment.author.login_name} on #{comment.post.subject} %author= comment.author.login_name %description diff --git a/app/views/posts/show.rss.haml b/app/views/posts/show.rss.haml index 2b4362225..4f260a038 100644 --- a/app/views/posts/show.rss.haml +++ b/app/views/posts/show.rss.haml @@ -5,6 +5,7 @@ %link= post_url(@post) - @post.comments.each do |comment| %item + %title Comment by #{comment.author.login_name} on #{comment.created_at.to_s} %author= comment.author.login_name %description diff --git a/spec/views/comments/index.rss.haml_spec.rb b/spec/views/comments/index.rss.haml_spec.rb index 73bf99b99..e5eeeac95 100644 --- a/spec/views/comments/index.rss.haml_spec.rb +++ b/spec/views/comments/index.rss.haml_spec.rb @@ -16,6 +16,10 @@ describe 'comments/index.rss.haml' do rendered.should contain "Recent comments on all posts" end + it 'shows item title' do + rendered.should contain "Comment by #{@author.login_name}" + end + it 'escapes html for link to post' do # it's then unescaped by 'render' so we don't actually look for < rendered.should contain '