Skip to content

Commit

Permalink
Fixes conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric de Villamil committed Sep 11, 2013
2 parents 1fd27ea + e305379 commit 79fa967
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 160 deletions.
10 changes: 0 additions & 10 deletions app/helpers/application_helper.rb
Expand Up @@ -80,16 +80,6 @@ def html(content, what = :all, deprecated = false)
content.html(what)
end

def author_link(article)
if this_blog.link_to_author and article.user and article.user.email.to_s.size>0
"<a href=\"mailto:#{h article.user.email}\">#{h article.user.name}</a>"
elsif article.user and article.user.name.to_s.size>0
h article.user.name
else
h article.author
end
end

def display_user_avatar(user_id, size='avatar', klass='alignleft')
user = User.find(user_id)

Expand Down
20 changes: 20 additions & 0 deletions app/helpers/authors_helper.rb
Expand Up @@ -15,4 +15,24 @@ def is_url?(str)
false
end
end

def author_link(article)
return h(article.author) if just_author?(article.user)
return h(article.user.name) if just_name?(article.user)
content_tag(:a, href: "mailto:#{h article.user.email}") { h(article.user.name) }
end

private

def just_author?(author)
author.name.blank? || author.nil?
end

def just_name?(author)
author.present? && !this_blog.link_to_author
end

def this_blog
@blog ||= Blog.default
end
end
133 changes: 64 additions & 69 deletions spec/controllers/articles_controller_spec.rb
Expand Up @@ -2,11 +2,9 @@
require 'spec_helper'

describe ArticlesController do
let!(:blog) { build_stubbed :blog }
let!(:blog) { create(:blog) }

before(:each) do
create :user
end
before(:each) { create :user }

it "should redirect category to /categories" do
get 'category'
Expand All @@ -20,7 +18,7 @@

describe 'index action' do
before :each do
FactoryGirl.create(:article)
create(:article)
get 'index'
end

Expand Down Expand Up @@ -206,31 +204,25 @@
end

describe ArticlesController, "nosettings" do
before(:each) do
@blog = Blog.new.save
end

let!(:blog) { create(:blog, settings: {}) }
it 'redirects to setup' do
get 'index'
response.should redirect_to(:controller => 'setup', :action => 'index')
response.should redirect_to(controller: 'setup', action: 'index')
end

end

describe ArticlesController, "nousers" do
before(:each) do
build_stubbed(:blog)
end

let!(:blog) { create(:blog) }
it 'redirects to signup' do
get 'index'
response.should redirect_to(:controller => 'accounts', :action => 'signup')
response.should redirect_to(controller: 'accounts', action: 'signup')
end
end

describe ArticlesController, "feeds" do
let!(:blog) { create(:blog) }

before(:each) do
build_stubbed(:blog)
@article1 = FactoryGirl.create(:article,
:created_at => Time.now - 1.day)
FactoryGirl.create(:trackback, :article => @article1, :published_at => Time.now - 1.day,
Expand Down Expand Up @@ -288,7 +280,7 @@

describe ArticlesController, "previewing" do
render_views
before(:each) { @blog = build_stubbed(:blog) }
let!(:blog) { create(:blog) }

describe 'with non logged user' do
before :each do
Expand All @@ -302,30 +294,27 @@
end

describe 'with logged user' do
before :each do
#TODO Delete after removing fixtures
Profile.delete_all
henri = FactoryGirl.create(:user, :login => 'henri', :profile => FactoryGirl.create(:profile_admin, :label => Profile::ADMIN))
@request.session = { :user => henri.id }
@article = FactoryGirl.create(:article)
end
let(:henri) { create(:user, login: 'henri', profile: create(:profile_admin, label: Profile::ADMIN)) }
let(:article) { create(:article, user: henri) }

before(:each) { @request.session = { user: henri.id } }

with_each_theme do |theme, view_path|
it "should render template #{view_path}/articles/read" do
@blog.theme = theme if theme
get :preview, :id => @article.id
blog.theme = theme if theme
get :preview, id: article.id
response.should render_template('articles/read')
end
end

it 'should assigns article define with id' do
get :preview, :id => @article.id
assigns[:article].should == @article
get :preview, :id => article.id
assigns[:article].should == article
end

it 'should assigns last article with id like parent_id' do
draft = FactoryGirl.create(:article, :parent_id => @article.id)
get :preview, :id => @article.id
draft = create(:article, parent_id: article.id)
get :preview, id: article.id
assigns[:article].should == draft
end
end
Expand Down Expand Up @@ -388,7 +377,7 @@
it 'should get good article with utf8 slug' do
build_stubbed(:blog)
utf8article = FactoryGirl.create(:utf8article, :permalink => 'ルビー',
:published_at => Time.utc(2004, 6, 2))
:published_at => Time.utc(2004, 6, 2))
get :redirect, :from => '2004/06/02/ルビー'
assigns(:article).should == utf8article
end
Expand All @@ -405,9 +394,9 @@
it 'should redirect to article' do
build_stubbed(:blog)
article = FactoryGirl.create(:article, :permalink => 'second-blog-article',
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
get :redirect, :from => "articles/2004/04/01/second-blog-article"
assert_response 301
response.should redirect_to("http://myblog.net/2004/04/01/second-blog-article")
Expand All @@ -416,9 +405,9 @@
it 'should redirect to article with url_root' do
b = build_stubbed(:blog, :base_url => "http://test.host/blog")
article = FactoryGirl.create(:article, :permalink => 'second-blog-article',
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
get :redirect, :from => "articles/2004/04/01/second-blog-article"
assert_response 301
response.should redirect_to("http://test.host/blog/2004/04/01/second-blog-article")
Expand All @@ -427,17 +416,17 @@
it 'should redirect to article with articles in url_root' do
b = build_stubbed(:blog, :base_url => "http://test.host/aaa/articles/bbb")
article = FactoryGirl.create(:article, :permalink => 'second-blog-article',
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
:published_at => '2004-04-01 02:00:00',
:updated_at => '2004-04-01 02:00:00',
:created_at => '2004-04-01 02:00:00')
get :redirect, :from => "articles/2004/04/01/second-blog-article"
assert_response 301
response.should redirect_to("http://test.host/aaa/articles/bbb/2004/04/01/second-blog-article")
end
end

describe 'with permalink_format like %title%.html' do
let!(:blog) { build_stubbed(:blog, :permalink_format => '/%title%.html') }
let!(:blog) { build_stubbed(:blog, :permalink_format => '/%title%.html') }

before(:each) do

Expand Down Expand Up @@ -514,7 +503,7 @@
describe 'rendering as atom feed' do
before(:each) do
@trackback1 = FactoryGirl.create(:trackback, :article => @article, :published_at => Time.now - 1.day,
:published => true)
:published => true)
get :redirect, :from => "#{@article.permalink}.html.atom"
end

Expand All @@ -528,7 +517,7 @@
describe 'rendering as rss feed' do
before(:each) do
@trackback1 = FactoryGirl.create(:trackback, :article => @article, :published_at => Time.now - 1.day,
:published => true)
:published => true)
get :redirect, :from => "#{@article.permalink}.html.rss"
end

Expand Down Expand Up @@ -607,41 +596,47 @@
end

describe ArticlesController, "assigned keywords" do
before do
@blog = build_stubbed(:blog)
create :user
end
before(:each) { create :user }

it 'article with categories should have meta keywords' do
@blog.permalink_format = '/%title%.html'
category = FactoryGirl.create(:category)
article = FactoryGirl.create(:article, :categories => [category])
get :redirect, :from => "#{article.permalink}.html"
assigns(:keywords).should == category.name
end
context "with default blog" do
let!(:blog) { create(:blog) }

it 'article with neither categories nor tags should not have meta keywords' do
@blog.permalink_format = '/%title%.html'
article = FactoryGirl.create(:article)
get :redirect, :from => "#{article.permalink}.html"
assigns(:keywords).should == ""
it 'index without option and no blog keywords should not have meta keywords' do
get 'index'
assigns(:keywords).should == ""
end
end

it 'index without option and no blog keywords should not have meta keywords' do
get 'index'
assigns(:keywords).should == ""
context "with blog meta keywords to 'publify, is, amazing'" do
let!(:blog) { create(:blog, meta_keywords: "publify, is, amazing") }

it 'index without option but with blog keywords should have meta keywords' do
get 'index'
expect(assigns(:keywords)).to eq("publify, is, amazing")
end
end

it 'index without option but with blog keywords should have meta keywords' do
@blog.meta_keywords = "publify, is, amazing"
get 'index'
assigns(:keywords).should == "publify, is, amazing"
context "with blog permalin to /%title%.html" do
let!(:blog) { create(:blog, permalink_format: '/%title%.html') }

it 'article with categories should have meta keywords' do
category = create(:category)
article = create(:article, categories: [category])
get :redirect, from: "#{article.permalink}.html"
assigns(:keywords).should == category.name
end

it 'article with neither categories nor tags should not have meta keywords' do
article = create(:article)
get :redirect, :from => "#{article.permalink}.html"
assigns(:keywords).should == ""
end
end
end

describe ArticlesController, "preview page" do
let!(:blog) { create(:blog) }
render_views
before(:each) { @blog = build_stubbed(:blog) }

describe 'with non logged user' do
before :each do
Expand All @@ -663,7 +658,7 @@

with_each_theme do |theme, view_path|
it "should render template #{view_path}/articles/view_page" do
@blog.theme = theme if theme
blog.theme = theme if theme
get :preview_page, :id => @page.id
response.should render_template('articles/view_page')
end
Expand Down
62 changes: 49 additions & 13 deletions spec/helpers/author_helper_spec.rb
@@ -1,22 +1,58 @@
require 'spec_helper'

describe AuthorsHelper, 'display_profile_item' do
include AuthorsHelper
describe AuthorsHelper do

it 'should display the item as a list item if show_item is true' do
item = display_profile_item(item = 'my@jabber.org', item_desc = 'Jabber:')
item.should have_selector('li', :content => 'Jabber: my@jabber.org')
end
describe :display_profile_item do
it 'should display the item as a list item if show_item is true' do
item = display_profile_item('my@jabber.org', 'Jabber:')
item.should have_selector('li', content: 'Jabber: my@jabber.org')
end

it 'should NOT display the item empty' do
item = display_profile_item('', 'Jabber:')
item.should be_nil
end

it 'should NOT display the item as a list item if show_item is false' do
item = display_profile_item(item = '', item_desc = 'Jabber:')
item.should be_nil
it 'should display a link if the item is an url' do
item = display_profile_item('http://twitter.com/mytwitter', 'Twitter:')
item.should have_selector('li') do
have_selector('a', content: 'http://twitter.com/mytwitter')
end
end
end

it 'should display a link if the item is an url' do
item = display_profile_item(item = 'http://twitter.com/mytwitter', item_desc = 'Twitter:')
item.should have_selector('li') do
have_selector('a', :content => 'http://twitter.com/mytwitter')
describe :author_link do
context "with an article" do
let(:article) { build(:article, user: author) }

context "with an author with a name to this article" do
let(:author) { build(:user, name: "Henri") }

context "with a link_to_author set in blog" do
let!(:blog) { create(:blog, link_to_author: true) }
it { expect(author_link(article)).to have_selector('a', href: "mailto:#{author.email}", content: author.name) }
end

context "with a no link_to_author set in blog" do
let!(:blog) { create(:blog, link_to_author: false) }
it { expect(author_link(article)).to eq(author.name) }
end
end

context "with an author without a name to this article" do
let(:author) { build(:user, name: "") }
let(:article) { build(:article, user: author, author: "Emile") }

context "with a link_to_author set in blog" do
let!(:blog) { create(:blog, link_to_author: true) }
it { expect(author_link(article)).to eq(article.author) }
end

context "with a no link_to_author set in blog" do
let!(:blog) { create(:blog, link_to_author: false) }
it { expect(author_link(article)).to eq(article.author) }
end
end
end
end

Expand Down

0 comments on commit 79fa967

Please sign in to comment.