2012-03-01 23:25:55 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Comment do
|
|
|
|
|
|
|
|
it "factory should be valid" do
|
|
|
|
Factory.build(:comment).should be_valid
|
|
|
|
end
|
2012-03-03 17:09:03 +00:00
|
|
|
|
|
|
|
describe "#as_json" do
|
|
|
|
let(:user) { Factory(:user) }
|
|
|
|
let(:comment) { Factory.build(:comment) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
comment.user = user
|
|
|
|
end
|
|
|
|
|
2012-03-04 11:06:03 +00:00
|
|
|
it "includes user comment creator properties user" do
|
2012-03-03 17:09:03 +00:00
|
|
|
hash = comment.as_json
|
|
|
|
hash.should include(:user)
|
|
|
|
hash[:user].should include("nickname")
|
2012-03-04 10:34:40 +00:00
|
|
|
hash[:user].should include("avatar_url")
|
|
|
|
hash[:user].should include("id")
|
2012-03-03 17:09:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should include comment.created" do
|
|
|
|
comment.as_json.should include :created
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-04 12:32:39 +00:00
|
|
|
describe "#created" do
|
|
|
|
let(:time) { Time.new(2012, 01, 03) }
|
|
|
|
let(:expected) { time.strftime("%Y-%m-%dT%H:%M:%S") }
|
|
|
|
let(:comment) { Factory.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
|
2012-03-01 23:25:55 +00:00
|
|
|
end
|