Move comment specs as comment decorator specs
This commit is contained in:
parent
ff33380b12
commit
9ddd44abb5
@ -2,7 +2,7 @@ class CommentDecorator < ApplicationDecorator
|
||||
decorates :comment
|
||||
|
||||
def created
|
||||
h.time_ago_in_words(created_at) + " ago"
|
||||
created_at && (h.time_ago_in_words(created_at) + " ago")
|
||||
end
|
||||
|
||||
def as_json(opts = nil)
|
||||
|
@ -2,4 +2,44 @@ require 'spec_helper'
|
||||
|
||||
describe CommentDecorator do
|
||||
before { ApplicationController.new.set_current_view_context }
|
||||
|
||||
let(:decorated_comment) { CommentDecorator.new(comment) }
|
||||
|
||||
describe "#as_json" do
|
||||
let(:comment) { FactoryGirl.build(:comment) }
|
||||
|
||||
it "includes user comment creator properties user" do
|
||||
hash = decorated_comment.as_json
|
||||
hash.should include(:user)
|
||||
hash[:user].should include("nickname")
|
||||
hash[:user].should include("avatar_url")
|
||||
hash[:user].should include("id")
|
||||
end
|
||||
|
||||
it "should include comment.created" do
|
||||
decorated_comment.as_json.should include 'created'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#created" do
|
||||
let(:comment) { stub_model(Comment) }
|
||||
|
||||
context "when created_at present" do
|
||||
before { comment.created_at = Time.now }
|
||||
|
||||
it "returns string" do
|
||||
decorated_comment.created.should be_kind_of(String)
|
||||
end
|
||||
end
|
||||
|
||||
context "no created_at" do
|
||||
before { comment.created_at = nil }
|
||||
|
||||
it "returns string" do
|
||||
decorated_comment.created.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -6,43 +6,4 @@ describe Comment do
|
||||
FactoryGirl.build(:comment).should be_valid
|
||||
end
|
||||
|
||||
describe "#as_json" do
|
||||
let(:user) { Factory(:user) }
|
||||
let(:comment) { FactoryGirl.build(:comment) }
|
||||
|
||||
before do
|
||||
comment.user = user
|
||||
end
|
||||
|
||||
it "includes user comment creator properties user" do
|
||||
hash = comment.as_json
|
||||
hash.should include(:user)
|
||||
hash[:user].should include("nickname")
|
||||
hash[:user].should include("avatar_url")
|
||||
hash[:user].should include("id")
|
||||
end
|
||||
|
||||
it "should include comment.created" do
|
||||
comment.as_json.should include :created
|
||||
end
|
||||
end
|
||||
|
||||
describe "#created" do
|
||||
let(:time) { Time.new(2012, 01, 03) }
|
||||
let(:expected) { time.strftime("%Y-%m-%dT%H:%M:%S") }
|
||||
let(:comment) { FactoryGirl.build(:comment) }
|
||||
|
||||
context "when created_at present" do
|
||||
before { comment.stub(:created_at).and_return(time) }
|
||||
|
||||
it "returns js parsable format" do
|
||||
comment.created.should == expected
|
||||
end
|
||||
end
|
||||
|
||||
context "no created_at" do
|
||||
it { comment.created_at.should be_nil }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user