diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2c91a3e5ff..50fe242581 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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
- "#{h article.user.name}"
- 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)
diff --git a/app/helpers/authors_helper.rb b/app/helpers/authors_helper.rb
index a6c9305403..dd213a0e73 100644
--- a/app/helpers/authors_helper.rb
+++ b/app/helpers/authors_helper.rb
@@ -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
diff --git a/spec/controllers/articles_controller_spec.rb b/spec/controllers/articles_controller_spec.rb
index a9ccd18c90..d24ff912d4 100644
--- a/spec/controllers/articles_controller_spec.rb
+++ b/spec/controllers/articles_controller_spec.rb
@@ -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'
@@ -20,7 +18,7 @@
describe 'index action' do
before :each do
- FactoryGirl.create(:article)
+ create(:article)
get 'index'
end
@@ -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,
@@ -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
@@ -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
@@ -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
@@ -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")
@@ -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")
@@ -427,9 +416,9 @@
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")
@@ -437,7 +426,7 @@
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
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/spec/helpers/author_helper_spec.rb b/spec/helpers/author_helper_spec.rb
index 24564ca343..9d88b695d7 100644
--- a/spec/helpers/author_helper_spec.rb
+++ b/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
diff --git a/spec/models/content_spec.rb b/spec/models/content_spec.rb
index 3804822483..d7a5f6ac22 100644
--- a/spec/models/content_spec.rb
+++ b/spec/models/content_spec.rb
@@ -2,6 +2,7 @@
require 'spec_helper'
describe Content do
+ context "with a simple blog" do
let!(:blog) { create(:blog) }
describe "#short_url" do
@@ -95,5 +96,20 @@
end
end
end
+ end
+
+ describe :generate_html do
+ context "with a blog with textile filter" do
+ let!(:blog) { create(:blog, comment_text_filter: 'textile') }
+
+ context "comment with italic and bold" do
+ let(:comment) {build(:comment, body: 'Comment body _italic_ *bold*')}
+
+ it { expect(comment.generate_html(:body)).to match(/\italic\<\/em\>/) }
+ it { expect(comment.generate_html(:body)).to match(/\bold\<\/strong\>/) }
+ end
+ end
+
+ end
end
diff --git a/spec/views/articles/read_spec.rb b/spec/views/articles/read_spec.rb
deleted file mode 100644
index a04847bbf1..0000000000
--- a/spec/views/articles/read_spec.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require 'spec_helper'
-
-describe "articles/read.html.erb" do
- with_each_theme do |theme, view_path|
- describe theme ? "with theme #{theme}" : "without a theme" do
- before(:each) do
- @controller.view_paths.unshift(view_path) if theme
-
- # we do not want to test article links and such
- view.stub(:article_links) { "" }
- view.stub(:category_links) { "" }
- view.stub(:tag_links) { "" }
-
- view.stub(:display_date_and_time) {|dt| dt.to_s}
-
- blog = stub_default_blog
- blog.comment_text_filter = "textile"
- @controller.action_name = "redirect"
-
- article = stub_full_article(Time.now - 2.hours)
- article.body = 'body'
- article.extended = 'extended content'
- article.stub(:allow_comments?).and_return(false)
-
- @c1 = stub_model(Comment, :created_at => Time.now - 2.seconds, :body => 'Comment body _italic_ *bold*')
- @c2 = stub_model(Comment, :created_at => Time.now, :body => 'Hello foo@bar.com http://www.bar.com')
-
- article.stub(:published_comments) { [@c1, @c2] }
-
- text_filter = FactoryGirl.build(:textile)
- TextFilter.stub(:find_by_name) { text_filter }
-
- assign(:article, article)
- render
- end
-
- it "should not have too many paragraph marks around body" do
- rendered.should have_selector("p", :content => "body")
- rendered.should_not have_selector("p>p", :content => "body")
- end
-
- it "should not have too many paragraph marks around extended contents" do
- rendered.should have_selector("p", :content => "extended content")
- rendered.should_not have_selector("p>p", :content => "extended content")
- end
-
- # FIXME: Move comment partial specs to their own spec file.
- it "should not have too many paragraph marks around comment contents" do
- rendered.should have_selector("p>em", :content => "italic")
- rendered.should have_selector("p>strong", :content => "bold")
- rendered.should_not have_selector("p>p>em", :content => "italic")
- end
-
- it "should automatically add links" do
- rendered.should have_selector("a", :href => "mailto:foo@bar.com",
- :content => "foo@bar.com")
- rendered.should have_selector("a", :href=>"http://www.bar.com",
- :content => "http://www.bar.com")
- end
-
- it "should show the comment creation times in the comment list" do
- rendered.should =~ /#{@c1.created_at.to_s}/
- rendered.should =~ /#{@c2.created_at.to_s}/
- end
- end
- end
-end
-