Skip to content

Commit

Permalink
Clean up specs to allow custom theme (even special ones)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Francois committed Sep 10, 2013
1 parent e33e2e3 commit 77cbe5d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 88 deletions.
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
12 changes: 6 additions & 6 deletions spec/helpers/author_helper_spec.rb
Expand Up @@ -4,19 +4,19 @@

describe :display_profile_item do
it 'should display the item as a list item if show_item is true' do
item = display_profile_item(item = 'my@jabber.org', show_item = true, item_desc = 'Jabber:')
item.should have_selector('li', :content => 'Jabber: my@jabber.org')
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 as a list item if show_item is false' do
item = display_profile_item(item = 'my@jabber.org', show_item = false, item_desc = 'Jabber:')
it 'should NOT display the item empty' do
item = display_profile_item('', 'Jabber:')
item.should be_nil
end

it 'should display a link if the item is an url' do
item = display_profile_item(item = 'http://twitter.com/mytwitter', show_item = true, item_desc = 'Twitter:')
item = display_profile_item('http://twitter.com/mytwitter', 'Twitter:')
item.should have_selector('li') do
have_selector('a', :content => 'http://twitter.com/mytwitter')
have_selector('a', content: 'http://twitter.com/mytwitter')
end
end
end
Expand Down
19 changes: 6 additions & 13 deletions spec/views/articles/read_spec.rb
@@ -1,31 +1,24 @@
require 'spec_helper'

describe "articles/read.html.erb" do
let!(:blog) { create(:blog, comment_text_filter: 'textile') }

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')
now = DateTime.new(2013,2,21,15,45)
article = create(:article, published_at: now, body: 'body', extended: 'extended content', allow_comments: false)

article.stub(:published_comments) { [@c1, @c2] }
@c1 = create(:comment, created_at: now + 1.hour, body: 'Comment body _italic_ *bold*', article: article, published: true)
@c2 = create(:comment, created_at: now + 18.minutes, body: 'Hello foo@bar.com http://www.bar.com', article: article, published: true)

text_filter = FactoryGirl.build(:textile)
TextFilter.stub(:find_by_name) { text_filter }
Expand Down

0 comments on commit 77cbe5d

Please sign in to comment.