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/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 000000000..024bd1578 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,39 @@ +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. + +## Committers + +- Alex Bayley / [Skud](https://github.com/Skud) +- 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) +- 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) +- Craig Read / [Catharz](https://github.com/Catharz) +- 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) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d6bc30bd1..c14b0123b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -2,12 +2,12 @@ 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 format.json { render json: @comments } + format.rss { render :layout => false } end end 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/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/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1ca2b5f94..de7c80091 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 @@ -23,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/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/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/comments/index.rss.haml b/app/views/comments/index.rss.haml new file mode 100644 index 000000000..5e4b227c5 --- /dev/null +++ b/app/views/comments/index.rss.haml @@ -0,0 +1,23 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - Recent comments on all posts + %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 + + :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/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/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..aabd178ac --- /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) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 8610257d1..9f4c0d12a 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -74,7 +74,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..f6244623d --- /dev/null +++ b/app/views/members/show.rss.haml @@ -0,0 +1,15 @@ + +%rss{:version => 2.0} + %channel + %title #{Growstuff::Application.config.site_name} - #{@member.login_name}'s recent posts + %link= member_url(@member) + - @posts.each do |post| + %item + %pubDate= post.created_at.to_s(:rfc822) + %link= post_url(post) + %guid= post_url(post) + %author= @member.login_name + %title= post.subject + %description + :escaped_markdown + #{ strip_tags post.body } diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index d359a342d..6e98960ad 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 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/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/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..12402d0cf --- /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 + - @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/app/views/posts/show.rss.haml b/app/views/posts/show.rss.haml new file mode 100644 index 000000000..4f260a038 --- /dev/null +++ b/app/views/posts/show.rss.haml @@ -0,0 +1,23 @@ + +%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 + %title Comment by #{comment.author.login_name} on #{comment.created_at.to_s} + %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/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..c60256ac9 --- /dev/null +++ b/lib/haml/filters/escaped_markdown.rb @@ -0,0 +1,17 @@ +require 'bluecloth' + +module Haml::Filters + module EscapedMarkdown + include Haml::Filters::Base + + 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/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 587d24407..128bcdd4e 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -14,7 +14,15 @@ describe CommentsController do comment = Comment.create! valid_attributes get :index, {} assigns(:comments).should eq([comment]) - assigns(:recent_comments).should eq([comment]) + 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 @@ -63,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/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/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/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5fe9c1ddd..bdae1ce48 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 @@ -34,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/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 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/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 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..e5eeeac95 --- /dev/null +++ b/spec/views/comments/index.rss.haml_spec.rb @@ -0,0 +1,32 @@ +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 '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 ' @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 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 diff --git a/spec/views/members/show.rss.builder_spec.rb b/spec/views/members/show.rss.haml_spec.rb similarity index 51% rename from spec/views/members/show.rss.builder_spec.rb rename to spec/views/members/show.rss.haml_spec.rb index 320229e3a..adb6e0bc3 100644 --- a/spec/views/members/show.rss.builder_spec.rb +++ b/spec/views/members/show.rss.haml_spec.rb @@ -1,11 +1,11 @@ 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, [ 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.builder', :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 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 diff --git a/spec/views/posts/index.rss.builder_spec.rb b/spec/views/posts/index.rss.haml_spec.rb similarity index 84% rename from spec/views/posts/index.rss.builder_spec.rb rename to spec/views/posts/index.rss.haml_spec.rb index f2b6c87e4..cd5f74c4d 100644 --- a/spec/views/posts/index.rss.builder_spec.rb +++ b/spec/views/posts/index.rss.haml_spec.rb @@ -1,10 +1,10 @@ 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) - assign(:recent_posts, [ + assign(:posts, [ FactoryGirl.build(:post, :id => 1, :author => @author), FactoryGirl.build(:post, :id => 2, :author => @author) ]) 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..2f2780d09 --- /dev/null +++ b/spec/views/posts/show.rss.haml_spec.rb @@ -0,0 +1,31 @@ +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 '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 '