Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fdv/publify
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric de Villamil committed Sep 4, 2013
2 parents 8058ec5 + 1f9b24e commit 5205937
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/models/note.rb
Expand Up @@ -14,10 +14,11 @@ class Note < Content

belongs_to :user
validates_presence_of :body
validates_uniqueness_of :permalink
validates_uniqueness_of :permalink, :guid
attr_accessor :push_to_twitter, :twitter_message

after_create :set_permalink, :shorten_url
before_create :create_guid

default_scope order("published_at DESC")

Expand Down
7 changes: 6 additions & 1 deletion app/views/shared/_atom_item_article.atom.builder
Expand Up @@ -6,9 +6,14 @@ feed.entry item, :id => "urn:uuid:#{item.guid}", :url => item.permalink_url do |
entry.email email if this_blog.link_to_author unless email.blank?
end

entry.title item.title, "type"=>"html"
if item.is_a?(Note)
entry.title item.body, "type"=>"html"
else
entry.title item.title, "type"=>"html"
end

if item.is_a?(Article)

item.categories.each do |category|
entry.category "term" => category.permalink, "label" => category.name, "scheme" => category.permalink_url
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/shared/_rss_item_article.rss.builder
@@ -1,5 +1,9 @@
xm.item do
xm.title item.title
if item.is_a?(Note)
xm.title item.body
else
xm.title item.title
end
content_html =
if item.password_protected?
"<p>This article is password protected. Please <a href='#{item.permalink_url}'>fill in your password</a> to read it</p>"
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Expand Up @@ -237,6 +237,7 @@
published true
state 'published'
text_filter {FactoryGirl.create(:markdown)}
guid
end

factory :unpublished_note, :parent => :note do |n|
Expand Down
42 changes: 28 additions & 14 deletions spec/models/note_spec.rb
@@ -1,6 +1,20 @@
# coding: utf-8
require 'spec_helper'

describe Note do
let!(:blog) { create(:blog) }

describe "validations" do
it { expect(create(:note)).to be_valid }

context "with an existing note" do
let(:existing_note) { create(:note) }

it { expect(build(:note, guid: existing_note.guid)).to be_invalid }
end
end
end

describe "Testing redirects" do
it "a new published status gets a redirect" do
FactoryGirl.create(:blog)
Expand All @@ -20,8 +34,8 @@
note = FactoryGirl.create(:note, :body => "A test tweet with a #hashtag")
text = note.html_preprocess(note.body, note.body)
text.should == "A test tweet with a <a href='https://twitter.com/search?q=%23hashtag&src=tren&mode=realtime'>#hashtag</a>"
end
end

it "should replace a @mention by a proper URL to the twitter account" do
note = FactoryGirl.create(:note, :body => "A test tweet with a @mention")
text = note.html_preprocess(note.body, note.body)
Expand All @@ -38,7 +52,7 @@
note = FactoryGirl.create(:note, :body => "A test tweet with a https://link.com")
text = note.html_preprocess(note.body, note.body)
text.should == "A test tweet with a <a href='https://link.com'>https://link.com</a>"
end
end
end

describe 'Testing notes scopes' do
Expand All @@ -50,15 +64,15 @@
it 'Published scope should not bring unpublished statuses' do
FactoryGirl.create(:note)
FactoryGirl.create(:unpublished_note)

notes = Note.published
notes.count.should == 1
end

it 'Published scope should not bring notes published in the future' do
FactoryGirl.create(:note)
FactoryGirl.create(:note, published_at: Time.now + 3.days )

notes = Note.published
notes.count.should == 1
end
Expand All @@ -75,7 +89,7 @@
subject { @note.permalink_url }
it { should == "http://myblog.net/note/#{@note.id}-this-is-a-note" }
end

it "should give a sanitized title" do
note = FactoryGirl.build(:note, :body => 'body with accents éèà')
note.body.to_permalink.should == 'body-with-accents-eea'
Expand Down Expand Up @@ -118,15 +132,15 @@ def valid_attributes
@note.body = 'somebody'
@note.should be_valid
end

it "should use sanitize title to set note name" do
@note.attributes = valid_attributes.except(:body)
@note.body = 'title with accents éèà'
@note.should be_valid
@note.save
@note.permalink.should == "#{@note.id}-title-with-accents-eea"
end

end

describe 'Given a note page' do
Expand All @@ -142,12 +156,12 @@ def valid_attributes
note = FactoryGirl.build(:note, twitter_message: "A message without URL")
note.instance_eval{ calculate_real_length }.should == 21
end

it "A twitter message with a short http URL should have its URL expanded to 20 chars" do
note = FactoryGirl.build(:note, twitter_message: "A message with a short URL http://foo.com")
note.instance_eval{ calculate_real_length }.should == 47
end

it "A twitter message with a short https URL should have its URL expanded to 21 chars" do
note = FactoryGirl.build(:note, twitter_message: "A message with a short URL https://foo.com")
note.instance_eval{ calculate_real_length }.should == 48
Expand All @@ -162,7 +176,7 @@ def valid_attributes
note = FactoryGirl.build(:note, twitter_message: "A message with a long URL http://foobarsomething.com?blablablablabla")
note.instance_eval{ calculate_real_length }.should == 46
end

it "A twitter message with a short https URL should have its URL expanded to 21 chars" do
note = FactoryGirl.build(:note, twitter_message: "A message with a long URL https://foobarsomething.com?blablablablabla")
note.instance_eval{ calculate_real_length }.should == 47
Expand All @@ -172,7 +186,7 @@ def valid_attributes
note = FactoryGirl.build(:note, twitter_message: "A message with a long URL ftp://foobarsomething.com?blablablablabla")
note.instance_eval{ calculate_real_length }.should == 45
end
end
end

describe 'Pushing a note to Twitter' do
before :each do
Expand All @@ -184,7 +198,7 @@ def valid_attributes
note = FactoryGirl.build(:note, :push_to_twitter => 0)
note.send_to_twitter.should == false
end

it 'a non configured blog and non configured user should not send a note to Twitter' do
FactoryGirl.create(:blog)
note = FactoryGirl.create(:note)
Expand All @@ -197,7 +211,7 @@ def valid_attributes
note = FactoryGirl.build(:note, user: user)
note.send_to_twitter.should == false
end

it 'a non configured blog and a configured user should not send a note to Twitter' do
FactoryGirl.build(:blog)
user = FactoryGirl.build(:user, twitter_oauth_token: "12345", twitter_oauth_token_secret: "67890")
Expand Down
18 changes: 18 additions & 0 deletions spec/views/articles/index_atom_feed_spec.rb
Expand Up @@ -158,5 +158,23 @@ def rendered_entry
parsed = Nokogiri::XML.parse(rendered)
parsed.css("entry").first
end

describe :title do

before(:each) do
assign(:articles, [article])
render
end

context "with a note" do
let(:article) { create(:note) }
it { expect(rendered_entry.css("title").text).to eq(article.body) }
end

context "with an article" do
let(:article) { create(:article) }
it { expect(rendered_entry.css("title").text).to eq(article.title) }
end
end
end

19 changes: 19 additions & 0 deletions spec/views/articles/index_rss_feed_spec.rb
Expand Up @@ -194,5 +194,24 @@ def rendered_entry
parsed = Nokogiri::XML.parse(rendered)
parsed.css("item").first
end

describe :title do

before(:each) do
assign(:articles, [article])
render
end

context "with a note" do
let(:article) { create(:note) }
it { expect(rendered_entry.css("title").text).to eq(article.body) }
end

context "with an article" do
let(:article) { create(:article) }
it { expect(rendered_entry.css("title").text).to eq(article.title) }
end
end

end

0 comments on commit 5205937

Please sign in to comment.