+
<%= render 'article_list', { :articles => @articles } -%>
diff --git a/spec/controllers/admin/content_controller_spec.rb b/spec/controllers/admin/content_controller_spec.rb
index 63dc1edfb2..ed99a627e0 100644
--- a/spec/controllers/admin/content_controller_spec.rb
+++ b/spec/controllers/admin/content_controller_spec.rb
@@ -19,8 +19,8 @@
end
it 'should restrict only by searchstring' do
- article = FactoryGirl.create(:article, :body => 'once uppon an originally time')
- get :index, :search => {:searchstring => 'originally'}
+ article = create(:article, body: 'once uppon an originally time')
+ get :index, search: {searchstring: 'originally'}
assigns(:articles).should == [article]
response.should render_template('index')
response.should be_success
diff --git a/spec/controllers/admin/pages_controller_spec.rb b/spec/controllers/admin/pages_controller_spec.rb
index 0d6434262d..ba0a2b7021 100644
--- a/spec/controllers/admin/pages_controller_spec.rb
+++ b/spec/controllers/admin/pages_controller_spec.rb
@@ -4,120 +4,126 @@
describe Admin::PagesController do
render_views
- before do
- @blog = create(:blog)
- @henri = create(:user,
- login: 'henri',
- profile: create(:profile_admin))
- request.session = { user: @henri.id }
+ def base_page(options={})
+ { :title => "posted via tests!",
+ :body => "A good body",
+ :name => "posted-via-tests",
+ :published => true }.merge(options)
end
- describe '#index' do
- it 'should response success' do
- get :index
- expect(response).to be_success
- expect(response).to render_template('index')
- expect(assigns(:pages)).to_not be_nil
- end
+ let!(:blog) { create(:blog) }
+
+ let(:user) { create(:user, profile: create(:profile_admin)) }
+ before(:each) { request.session = { user: user.id } }
- it 'should response success with :page args' do
- get :index, page: 1
- expect(response).to be_success
- expect(response).to render_template('index')
- expect(assigns(:pages)).to_not be_nil
+ describe :index do
+ context "without params" do
+ before(:each) { get :index }
+ it { expect(response).to be_success }
+ it { expect(response).to render_template('index') }
+ it { expect(assigns(:pages)).to_not be_nil }
end
+ context "with page 1" do
+ before(:each) { get :index, page: 1 }
+ it { expect(response).to be_success }
+ it { expect(response).to render_template('index') }
+ it { expect(assigns(:pages)).to_not be_nil }
+ end
end
- describe "new" do
- context "without page params" do
- it "should render template new and has a page object" do
- get :new
- expect(response).to be_success
- expect(response).to render_template("new")
- expect(assigns(:page)).to_not be_nil
+ describe :new do
+ context "using get" do
+ context "without page params" do
+ it "should render template new and has a page object" do
+ get :new
+ expect(response).to be_success
+ expect(response).to render_template("new")
+ expect(assigns(:page)).to_not be_nil
+ end
+
+ it "should assign to current user" do
+ get :new
+ expect(assigns(:page).user).to eq(user)
+ end
+
+ it "should have a text filter" do
+ get :new
+ assigns(:page).text_filter.name.should eq 'textile'
+ end
end
+ end
- it "should assign to current user" do
- get :new
- expect(assigns(:page).user).to eq(@henri)
- end
+ context "using post" do
+ it "test_create" do
+ post :new, :page => { :name => "new_page", :title => "New Page Title",
+ :body => "Emphasis _mine_, arguments *strong*" }
- it "should have a text filter" do
- get :new
- assigns(:page).text_filter.name.should eq 'textile'
- end
- end
- end
+ new_page = Page.find(:first, :order => "id DESC")
- it "test_create" do
- post :new, :page => { :name => "new_page", :title => "New Page Title",
- :body => "Emphasis _mine_, arguments *strong*" }
+ assert_equal "new_page", new_page.name
- new_page = Page.find(:first, :order => "id DESC")
+ assert_response :redirect, :action => "show", :id => new_page.id
- assert_equal "new_page", new_page.name
+ # XXX: The flash is currently being made available improperly to tests (scoop)
+ assert_equal "Page was successfully created.", flash[:notice]
+ end
- assert_response :redirect, :action => "show", :id => new_page.id
+ it 'should create a published page with a redirect' do
+ post(:new, 'page' => base_page)
+ assigns(:page).redirects.count.should == 1
+ end
- # XXX: The flash is currently being made available improperly to tests (scoop)
- assert_equal "Page was successfully created.", flash[:notice]
- end
+ it 'should create an unpublished page without a redirect' do
+ post(:new, 'page' => base_page({:published => false}))
+ assigns(:page).redirects.count.should == 0
+ end
- describe "test_edit" do
- before(:each) do
- @page = FactoryGirl.create(:page)
- get :edit, :id => @page.id
- end
+ it 'should create a page published in the future without a redirect' do
+ pending ":published_at parameter is currently ignored"
+ post(:new, 'page' => base_page({:published_at => (Time.now + 1.hour).to_s}))
+ assigns(:page).redirects.count.should == 0
+ end
- it 'should render edit template' do
- assert_response :success
- assert_template "edit"
- assert_not_nil assigns(:page)
- assert_equal @page, assigns(:page)
end
-
end
- it 'test_update' do
- page = FactoryGirl.create(:page)
- post :edit, :id => page.id, :page => { :name => "markdown-page", :title => "Markdown Page",
- :body => "Adding a [link](http://www.publify.co/) here" }
-
- assert_response :redirect, :action => "show", :id => page.id
-
- # XXX: The flash is currently being made available improperly to tests (scoop)
- #assert_equal "Page was successfully updated.", flash[:notice]
- end
+ describe :edit do
+ context "using get" do
+ before(:each) do
+ @page = FactoryGirl.create(:page)
+ get :edit, :id => @page.id
+ end
- it "test_destroy" do
- page = FactoryGirl.create(:page)
- post :destroy, :id => page.id
- assert_response :redirect, :action => "list"
- assert_raise(ActiveRecord::RecordNotFound) { Page.find(page.id) }
- end
+ it 'should render edit template' do
+ assert_response :success
+ assert_template "edit"
+ assert_not_nil assigns(:page)
+ assert_equal @page, assigns(:page)
+ end
- def base_page(options={})
- { :title => "posted via tests!",
- :body => "A good body",
- :name => "posted-via-tests",
- :published => true }.merge(options)
- end
+ end
- it 'should create a published page with a redirect' do
- post(:new, 'page' => base_page)
- assigns(:page).redirects.count.should == 1
- end
+ context "using post" do
+ it 'test_update' do
+ page = FactoryGirl.create(:page)
+ post :edit, :id => page.id, :page => { :name => "markdown-page", :title => "Markdown Page",
+ :body => "Adding a [link](http://www.publify.co/) here" }
- it 'should create an unpublished page without a redirect' do
- post(:new, 'page' => base_page({:published => false}))
- assigns(:page).redirects.count.should == 0
+ assert_response :redirect, :action => "show", :id => page.id
+ # XXX: The flash is currently being made available improperly to tests (scoop)
+ #assert_equal "Page was successfully updated.", flash[:notice]
+ end
+ end
end
- it 'should create a page published in the future without a redirect' do
- pending ":published_at parameter is currently ignored"
- post(:new, 'page' => base_page({:published_at => (Time.now + 1.hour).to_s}))
- assigns(:page).redirects.count.should == 0
+ describe :destroy do
+ it "test_destroy" do
+ page = FactoryGirl.create(:page)
+ post :destroy, :id => page.id
+ assert_response :redirect, :action => "list"
+ assert_raise(ActiveRecord::RecordNotFound) { Page.find(page.id) }
+ end
end
describe 'insert_editor action' do
@@ -137,3 +143,4 @@ def base_page(options={})
end
end
end
+
diff --git a/spec/factories.rb b/spec/factories.rb
index 795a1851e6..8ea981bb5d 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -2,39 +2,16 @@
# Factory definitions
FactoryGirl.define do
- sequence :name do |n|
- "name_#{n}"
- end
-
- sequence :user do |n|
- "user#{n}"
- end
-
- sequence :email do |n|
- "user#{n}@example.com"
- end
-
- sequence :guid do |n|
- "deadbeef#{n}"
- end
-
- sequence :label do |n|
- "lab_#{n}"
- end
-
- sequence :file_name do |f|
- "file_name_#{f}"
- end
-
- sequence :category do |n|
- "c_#{n}"
- end
-
- basetime = Time.now
- sequence :time do |n|
- basetime - n
- end
+ sequence :name do |n|; "name_#{n}"; end
+ sequence :body do |n|; "body #{n}" * (n+3 % 5) ; end
+ sequence :user do |n|; "user#{n}" ; end
+ sequence :email do |n|; "user#{n}@example.com" ; end
+ sequence :guid do |n|; "deadbeef#{n}" ; end
+ sequence :label do |n|; "lab_#{n}" ; end
+ sequence :file_name do |f|; "file_name_#{f}" ; end
+ sequence :category do |n|; "c_#{n}" ; end
+ sequence :time do |n|; DateTime.new(2012,3,26,19,56) - n ; end
factory :user do
login { FactoryGirl.generate(:user) }
@@ -241,9 +218,9 @@
end
factory :page do
- name 'page_one'
+ name {FactoryGirl.generate(:name)}
title 'Page One Title'
- body 'ho ho ho'
+ body {FactoryGirl.generate(:body)}
created_at '2005-05-05 01:00:01'
published_at '2005-05-05 01:00:01'
updated_at '2005-05-05 01:00:01'
@@ -262,7 +239,7 @@
state 'published'
text_filter {FactoryGirl.create(:markdown)}
end
-
+
factory :unpublished_note, :parent => :note do |n|
n.published false
end
diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb
index 4bfd25b5de..69a1f1e945 100644
--- a/spec/models/article_spec.rb
+++ b/spec/models/article_spec.rb
@@ -631,46 +631,50 @@ def assert_sets_trigger(art)
end
end
- describe ".search_with_pagination" do
- #TODO move those kind of test to a "integration specs" that can be run only for integration
- context "given some datas" do
- it "returns an empty array when no article and no params" do
- Article.search_with_pagination({}, {page: nil, per_page: 12}).should be_empty
- end
-
- it "returns article" do
- article = FactoryGirl.create(:article)
- Article.search_with_pagination({}, {page: nil, per_page: 12}).should eq([article])
- end
+ describe :search_with do
+ subject { Article.search_with(params) }
- it "returns only published article where search params ask about published state" do
- published_article = FactoryGirl.create(:article, state: 'published')
- article = FactoryGirl.create(:article, state: 'draft')
- Article.search_with_pagination({state: 'published'}, {page: nil, per_page: 12}).should eq([published_article])
- end
+ context "without article" do
+ let(:params) { nil }
+ it { expect(subject).to be_empty }
+ end
- it "returns only quantity of article ask in per_page" do
- article = FactoryGirl.create(:article, state: 'published')
- out_of_per_page_article = FactoryGirl.create(:article, state: 'draft')
+ context "with an article" do
+ let(:params) { nil }
+ let!(:article) { create(:article) }
+ it { expect(subject).to eq([article]) }
+ end
- Article.search_with_pagination({}, { page: nil, per_page: 1 }).should have(1).item
- end
+ context "with two article but only one matching searchstring" do
+ let(:params) { {searchstring: 'match the string'} }
+ let!(:not_found_article) { create(:article) }
+ let!(:article) { create(:article, body: 'this match the string of article') }
+ it { expect(subject).to eq([article]) }
+ end
- it "returns both published and draft articles by default" do
- article = FactoryGirl.create(:article, state: 'published')
- draft_article = FactoryGirl.create(:article, state: 'draft')
- result = Article.search_with_pagination({}, {page: nil, per_page: 12})
- result.count.should eq 2
- end
+ context "with two articles with differents states and published params" do
+ let(:params) { {state: 'published'} }
+ let!(:article) { create(:article, state: 'published') }
+ let!(:draft_article) { create(:article, state: 'draft') }
+ it { expect(subject).to eq([article]) }
+ end
- it "returns article of search categorie" do
- show_category = FactoryGirl.create(:category, name: 'show')
- hide_category = FactoryGirl.create(:category, name: 'not_show')
- article = FactoryGirl.create(:article, categories: [show_category])
- hide_article = FactoryGirl.create(:article, categories: [hide_category])
- Article.search_with_pagination({category: show_category.id}, {page: nil, per_page: 12}).should eq([article])
- end
+ context "with two articles with differents states and no params" do
+ let(:params) { nil }
+ let(:now) { DateTime.new(2011,3,12) }
+ let!(:article) { create(:article, state: 'published', created_at: now) }
+ let!(:last_draft_article) { create(:article, state: 'draft', created_at: now + 2.days, published_at: nil) }
+ let!(:draft_article) { create(:article, state: 'draft', created_at: now + 20.days, published_at:nil) }
+ it { expect(subject).to eq([article, draft_article, last_draft_article]) }
+ end
+ context "with two articles in two catageory" do
+ let(:show_category) { create(:category, name: 'show') }
+ let(:not_show_category) { create(:category, name: 'not_show') }
+ let(:params) { {category: show_category.id } }
+ let!(:article) { create(:article, categories: [show_category]) }
+ let!(:bad_category_article) { create(:article, categories: [not_show_category]) }
+ it { expect(subject).to eq([article]) }
end
end
diff --git a/spec/models/content_spec.rb b/spec/models/content_spec.rb
index f5b5113ed5..3804822483 100644
--- a/spec/models/content_spec.rb
+++ b/spec/models/content_spec.rb
@@ -2,9 +2,7 @@
require 'spec_helper'
describe Content do
- before do
- @blog = stub_default_blog
- end
+ let!(:blog) { create(:blog) }
describe "#short_url" do
before do
@@ -15,9 +13,7 @@
end
describe "normally" do
- before do
- @blog.stub(:base_url) { "http://myblog.net" }
- end
+ let!(:blog) { create(:blog, base_url: "http://myblog.net") }
it "returns the blog's base url combined with the redirection's from path" do
@content.should be_published
@@ -26,9 +22,7 @@
end
describe "when the blog is in a sub-uri" do
- before do
- @blog.stub(:base_url) { "http://myblog.net/blog" }
- end
+ let!(:blog) { create(:blog, base_url: "http://myblog.net/blog") }
it "includes the sub-uri path" do
@content.short_url.should == "http://myblog.net/blog/foo"
@@ -58,36 +52,48 @@
end
end
- describe "#function_search_all_posts" do
- it "returns empty array when nil given" do
- Content.function_search_all_posts(nil).should be_empty
- end
+ describe :search_posts_with do
+ context "with an simple article" do
+ subject { Content.search_with(params) }
- it "returns article that match with searchstring" do
- expected_function = ['searchstring(search_hash[:searchstring])']
- Content.function_search_all_posts({searchstring: 'something'}).should eq expected_function
- end
+ context "with nil params" do
+ let(:params) { nil }
+ it { expect(subject).to be_empty }
+ end
- it "returns article that match with published_at" do
- expected_function = ['published_at_like(search_hash[:published_at])']
- Content.function_search_all_posts({published_at: '2012-02'}).should eq expected_function
- end
+ context "with a matching searchstring article" do
+ let(:params) { {searchstring: 'a search string'} }
+ let!(:match_article) { create(:article, body: 'there is a search string here') }
+ it { expect(subject).to eq([match_article]) }
+ end
- it "returns article that match with user_id" do
- expected_function = ['user_id(search_hash[:user_id])']
- Content.function_search_all_posts({user_id: '1'}).should eq expected_function
- end
+ context "with an article published_at" do
+ let(:params) { {published_at: '2012-02'} }
+ let!(:article) { create(:article) }
+ let!(:match_article) { create(:article, published_at: DateTime.new(2012,2,13)) }
+ it { expect(subject).to eq([match_article]) }
+ end
- it "returns article that match with not published" do
- expected_function = ['not_published']
- Content.function_search_all_posts({published: '0'}).should eq expected_function
- end
+ context "with same user_id article" do
+ let(:params) { {user_id: '13'} }
+ let!(:article) { create(:article) }
+ let!(:match_article) { create(:article, user_id: 13) }
+ it { expect(subject).to eq([match_article]) }
+ end
- it "returns article that match with published" do
- expected_function = ['published']
- Content.function_search_all_posts({published: '1'}).should eq expected_function
- end
+ context "with not published status article" do
+ let(:params) { {published: '0' } }
+ let!(:article) { create(:article) }
+ let!(:match_article) { create(:article, published: false) }
+ it { expect(subject).to eq([match_article]) }
+ end
+ context "with published status article" do
+ let(:params) { {published: '1' } }
+ let!(:article) { create(:article, published: true) }
+ it { expect(subject).to eq([article]) }
+ end
+ end
end
end
diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb
index 9d689394a0..42bddc84c0 100644
--- a/spec/models/page_spec.rb
+++ b/spec/models/page_spec.rb
@@ -2,126 +2,82 @@
require 'spec_helper'
describe Page do
- describe "#initialize" do
- it "accepts a settings field in its parameter hash" do
- Page.new({"password" => 'foo'})
+ let!(:blog) { create(:blog) }
+
+ describe :name= do
+ context "when build a page without name" do
+ let(:page) { create(:page, name: nil, title: 'A title') }
+ it { expect(page.name).to eq('a-title') }
end
end
-end
-describe "Testing redirects" do
- it "a new published page gets a redirect" do
- FactoryGirl.create(:blog)
- a = Page.create(:title => "Some title", :body => "some text", :published => true)
- a.should be_valid
- a.redirects.first.should_not be_nil
- a.redirects.first.to_path.should == a.permalink_url
+ describe :permalink do
+ context "with an existing page" do
+ let(:page) { create(:page, name: 'page_one') }
+ it { expect(page.permalink_url).to eq('http://myblog.net/pages/page_one') }
+ end
end
- it "a new unpublished page should not get a redirect" do
- FactoryGirl.create(:blog)
- a = Page.create(:title => "Some title", :body => "some text", :published => true)
- a = Page.create(:title => "Another title", :body => "some text", :published => false)
- a.redirects.first.should be_nil
- end
+ describe "validations" do
+ context "with an existing page name" do
+ let!(:page) { create(:page, name: 'page_one') }
+ it { expect(build(:page, name: page.name)).to be_invalid }
+ end
- it "Changin a published article permalink url should only change the to redirection" do
- FactoryGirl.create(:blog)
- a = Page.create(:title => "Third title", :body => "some text", :published => true)
- a.should be_valid
- a.redirects.first.should_not be_nil
- a.redirects.first.to_path.should == a.permalink_url
- r = a.redirects.first.from_path
-
- a.name = "some-new-permalink"
- a.save
- a.redirects.first.should_not be_nil
- a.redirects.first.to_path.should == a.permalink_url
- a.redirects.first.from_path.should == r
- end
-end
+ context "without name" do
+ it { expect(build(:page, name: nil)).to be_valid }
+ end
-describe 'Given the fixture :first_page' do
- before(:each) do
- FactoryGirl.create(:blog)
- @page = FactoryGirl.create(:page)
- end
+ context "without body" do
+ it { expect(build(:page, body: nil)).to be_invalid }
+ end
- describe "#permalink_url" do
- subject { @page.permalink_url }
- it { should == 'http://myblog.net/pages/page_one' }
+ context "without title" do
+ it { expect(build(:page, title: nil)).to be_invalid }
+ end
end
- it 'Pages cannot have the same name' do
- Page.new(:name => @page.name, :body => @page.body, :title => @page.title).should_not be_valid
- Page.new(:name => @page.name, :body => 'body', :title => 'title').should_not be_valid
- end
-
- it "should give a sanitized title" do
- page = FactoryGirl.build(:page, :title => 'title with accents éèà')
- page.title.to_permalink.should == 'title-with-accents-eea'
+ describe :default_text_filter do
+ it { expect(create(:page).default_text_filter.name).to eq(blog.text_filter) }
end
-end
-class Hash
- def except(*keys)
- self.reject { |k,v| keys.include? k.to_sym }
- end
+ describe :search_with do
+ context "with an simple page" do
+ let!(:page) { create(:page) }
- def only(*keys)
- self.dup.reject { |k, v| !keys.include? k.to_sym }
- end
-end
+ subject { Page.search_with(params) }
-describe 'Given no pages' do
- def valid_attributes
- { :title => 'title', :body => 'body'}
- end
+ context "with nil params" do
+ let(:params) { nil }
+ it { expect(subject).to eq([page]) }
+ end
- before(:each) do
- Page.delete_all
- @page = Page.new
- end
+ context "with a matching searchstring page" do
+ let(:params) { {searchstring: 'foobar'} }
+ let!(:match_page) { create(:page, title: 'foobar') }
+ it { expect(subject).to eq([match_page]) }
+ end
- it 'An empty page is invalid' do
- @page.should_not be_valid
+ context "with 2 pages with title aaa and zzz" do
+ let!(:last_page) { create(:page, title: 'ZZZ', published: true) }
+ let!(:first_page) { create(:page, title: 'AAA', published: true) }
+ let(:params) { {published: '1'} }
+ it { expect(subject).to eq([first_page, page, last_page]) }
+ end
+ end
end
- it 'A page is valid with a title and body' do
- @page.attributes = valid_attributes
- @page.should be_valid
- end
+ describe :redirects do
+ context "with a simple page" do
+ let(:page) { create(:page) }
+ it { expect(page.redirects.first.to_path).to eq(page.permalink_url) }
+ end
- it 'A page is invalid without a title' do
- @page.attributes = valid_attributes.except(:title)
- @page.should_not be_valid
- @page.errors[:title].should == ["can't be blank"]
- @page.title = 'sometitle'
- @page.should be_valid
- end
+ context "with an unpublished page" do
+ let(:page) { create(:page, published: false) }
+ it { expect(page.redirects).to be_empty}
+ end
- it 'A page is invalid without a body' do
- @page.attributes = valid_attributes.except(:body)
- @page.should_not be_valid
- @page.errors[:body].should == ["can't be blank"]
- @page.body = 'somebody'
- @page.should be_valid
end
-
- it "should use sanitize title to set page name" do
- @page.attributes = valid_attributes.except(:title)
- @page.title = 'title with accents éèà'
- @page.should be_valid
- @page.save
- @page.name.should == "title-with-accents-eea"
- end
-
end
-describe 'Given a valid page' do
- it 'default filter should be fetched from the blog' do
- FactoryGirl.create(:blog)
- @page = Page.new()
- @page.default_text_filter.name.should == Blog.default.text_filter
- end
-end