aboutsummaryrefslogtreecommitdiffstats
path: root/spec/requests/refinery
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/refinery')
-rw-r--r--spec/requests/refinery/blog/admin/categories_spec.rb101
-rw-r--r--spec/requests/refinery/blog/admin/posts_spec.rb161
-rw-r--r--spec/requests/refinery/blog/categories_spec.rb14
-rw-r--r--spec/requests/refinery/blog/posts_spec.rb80
4 files changed, 315 insertions, 41 deletions
diff --git a/spec/requests/refinery/blog/admin/categories_spec.rb b/spec/requests/refinery/blog/admin/categories_spec.rb
index c1809f7..9d4ddf3 100644
--- a/spec/requests/refinery/blog/admin/categories_spec.rb
+++ b/spec/requests/refinery/blog/admin/categories_spec.rb
@@ -1,8 +1,9 @@
+# encoding: utf-8
require 'spec_helper'
describe "Categories admin" do
refinery_login_with :refinery_user
-
+
let(:title) { "lol" }
it "can create categories" do
@@ -17,4 +18,102 @@ describe "Categories admin" do
category = Refinery::Blog::Category.first
category.title.should eq(title)
end
+
+ context "with translations" do
+ before(:each) do
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
+ blog_page = Globalize.with_locale(:en) { Factory.create(:page, :link_url => "/blog", :title => "Blog") }
+ Globalize.with_locale(:ru) do
+ blog_page.title = 'блог'
+ blog_page.save
+ end
+ end
+
+ describe "add a category with title for default locale" do
+ before do
+ Globalize.locale = :en
+ visit refinery.blog_admin_posts_path
+ click_link "Create new category"
+ fill_in "Title", :with => "Testing Category"
+ click_button "Save"
+ @c = Refinery::Blog::Category.find_by_title("Testing Category")
+ end
+
+ it "suceeds" do
+ page.should have_content("'#{@c.title}' was successfully added.")
+ Refinery::Blog::Category.count.should eq(1)
+ end
+
+ it "shows locale flag for category" do
+ click_link "Manage"
+ within "#category_#{@c.id}" do
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
+ end
+ end
+
+ it "shows up in blog page for default locale" do
+ visit refinery.blog_root_path
+ within "#categories" do
+ page.should have_selector('li')
+ end
+ end
+
+ it "does not show up in blog page for secondary locale" do
+ visit refinery.blog_root_path(:locale => :ru)
+ page.should_not have_selector('#categories')
+ end
+
+ end
+
+ describe "add a category with title for secondary locale" do
+
+ let(:ru_category_title) { 'категория' }
+
+ before do
+ visit refinery.blog_admin_posts_path
+ click_link "Create new category"
+ within "#switch_locale_picker" do
+ click_link "Ru"
+ end
+ fill_in "Title", :with => ru_category_title
+ click_button "Save"
+ @c = Refinery::Blog::Category.find_by_title(ru_category_title)
+ end
+
+ it "suceeds" do
+ page.should have_content("'#{@c.title}' was successfully added.")
+ Refinery::Blog::Category.count.should eq(1)
+ end
+
+ it "shows locale flag for category" do
+ click_link "Manage"
+ within "#category_#{@c.id}" do
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
+ end
+ end
+
+ it "does not show locale flag for primary locale" do
+ click_link "Manage"
+ within "#category_#{@c.id}" do
+ page.should_not have_css("img[src='/assets/refinery/icons/flags/en.png']")
+ end
+ end
+
+ it "does not shows up in blog page for default locale" do
+ visit refinery.blog_root_path
+ page.should_not have_selector('#categories')
+ end
+
+ it "shows up in blog page for secondary locale" do
+ visit refinery.blog_root_path(:locale => :ru)
+ within "#categories" do
+ page.should have_selector('li')
+ end
+ end
+
+
+ end
+
+
+ end
end
diff --git a/spec/requests/refinery/blog/admin/posts_spec.rb b/spec/requests/refinery/blog/admin/posts_spec.rb
index 7972162..b298b49 100644
--- a/spec/requests/refinery/blog/admin/posts_spec.rb
+++ b/spec/requests/refinery/blog/admin/posts_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require "spec_helper"
module Refinery
@@ -5,7 +6,7 @@ module Refinery
module Admin
describe Post do
refinery_login_with :refinery_user
-
+
let!(:blog_category) { FactoryGirl.create(:blog_category, :title => "Video Games") }
context "when no blog posts" do
@@ -46,7 +47,7 @@ module Refinery
end
it "should be the only blog post" do
- subject.class.all.size.should eq(1)
+ subject.class.count.should eq(1)
end
it "should belong to me" do
@@ -73,7 +74,7 @@ module Refinery
end
it "should be the only blog post" do
- subject.class.all.size.should eq(1)
+ subject.class.count.should eq(1)
end
it "should have the specified tags" do
@@ -84,7 +85,9 @@ module Refinery
end
context "when has blog posts" do
- let!(:blog_post) { FactoryGirl.create(:blog_post) }
+ let!(:blog_post) do
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_post) }
+ end
describe "blog post listing" do
before(:each) { visit refinery.blog_admin_posts_path }
@@ -169,6 +172,156 @@ module Refinery
end
end
end
+
+ context "with translations" do
+ before(:each) do
+ Globalize.locale = :en
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
+ blog_page = Factory.create(:page, :link_url => "/blog", :title => "Blog")
+ Globalize.with_locale(:ru) do
+ blog_page.title = 'блог'
+ blog_page.save
+ end
+ visit refinery.blog_admin_posts_path
+ end
+
+ describe "add a blog post with title for default locale" do
+ before do
+ click_link "Create new post"
+ fill_in "Title", :with => "Post"
+ fill_in "post_body", :with => "One post in my blog"
+ click_button "Save"
+ @p = Refinery::Blog::Post.find_by_title("Post")
+ end
+
+ it "succeeds" do
+ page.should have_content("'Post' was successfully added.")
+ Refinery::Blog::Post.count.should eq(1)
+ end
+
+ it "shows locale flag for post" do
+
+ within "#post_#{@p.id}" do
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
+ end
+ end
+
+ it "shows up in blog page for default locale" do
+ visit refinery.blog_root_path
+ page.should have_selector("#post_#{@p.id}")
+ end
+
+ it "does not show up in blog page for secondary locale" do
+ visit refinery.blog_root_path(:locale => :ru)
+ page.should_not have_selector("#post_#{@p.id}")
+ end
+
+ end
+
+ describe "add a blog post with title only for secondary locale" do
+
+ let(:ru_page_title) { 'Новости' }
+
+ before do
+ click_link "Create new post"
+ within "#switch_locale_picker" do
+ click_link "Ru"
+ end
+ fill_in "Title", :with => ru_page_title
+ fill_in "post_body", :with => "One post in my blog"
+ click_button "Save"
+ @p = Refinery::Blog::Post.find_by_title("Новости")
+ end
+
+ it "succeeds" do
+ page.should have_content("was successfully added.")
+ Refinery::Blog::Post.count.should eq(1)
+ end
+
+ it "shows title in secondary locale" do
+ within "#post_#{@p.id}" do
+ page.should have_content(ru_page_title)
+ end
+ end
+
+ it "shows locale flag for post" do
+ within "#post_#{@p.id}" do
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
+ end
+ end
+
+ it "does not show locale flag for primary locale" do
+ within "#post_#{@p.id}" do
+ page.should_not have_css("img[src='/assets/refinery/icons/flags/en.png']")
+ end
+ end
+
+ it "does not show up in blog page for default locale" do
+ visit refinery.blog_root_path
+ page.should_not have_selector("#post_#{@p.id}")
+ end
+
+ it "shows up in blog page for secondary locale" do
+ visit refinery.blog_root_path(:locale => :ru)
+ page.should have_selector("#post_#{@p.id}")
+ end
+
+ end
+
+ context "with a blog post in both locales" do
+
+ let!(:blog_post) do
+ _blog_post = Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => 'First Post') }
+ Globalize.with_locale(:ru) do
+ _blog_post.title = 'Домашняя страница'
+ _blog_post.save
+ end
+ _blog_post
+ end
+
+ before(:each) do
+ visit refinery.blog_admin_posts_path
+ end
+
+ it "shows both locale flags for post" do
+ within "#post_#{blog_post.id}" do
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
+ end
+ end
+
+ describe "edit the post in english" do
+ it "succeeds" do
+
+ within "#post_#{blog_post.id}" do
+ click_link("En")
+ end
+ current_path.should == refinery.edit_blog_admin_post_path(blog_post)
+ fill_in "Title", :with => "New Post Title"
+ click_button "Save"
+
+ page.should_not have_content(blog_post.title)
+ page.should have_content("'New Post Title' was successfully updated.")
+ end
+ end
+
+ describe "edit the post in secondary locale" do
+ it "succeeds" do
+ within "#post_#{blog_post.id}" do
+ click_link("Ru")
+ end
+
+ fill_in "Title", :with => "Нов"
+ click_button "Save"
+
+ page.should_not have_content(blog_post.title)
+ page.should have_content("'Нов' was successfully updated.")
+ end
+ end
+
+ end
+ end
+
end
end
end
diff --git a/spec/requests/refinery/blog/categories_spec.rb b/spec/requests/refinery/blog/categories_spec.rb
index 3834992..ba96b1b 100644
--- a/spec/requests/refinery/blog/categories_spec.rb
+++ b/spec/requests/refinery/blog/categories_spec.rb
@@ -6,15 +6,19 @@ module Refinery
context "has one category and post" do
before(:each) do
- @post = FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
- @category = FactoryGirl.create(:blog_category, :title => "Video Games")
- @post.categories << @category
- @post.save!
+ post = Globalize.with_locale(:en) do
+ FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
+ end
+ @category = Globalize.with_locale(:en) do
+ FactoryGirl.create(:blog_category, :title => "Video Games")
+ end
+ post.categories << @category
+ post.save!
end
describe "show categories blog posts" do
- before(:each) { visit refinery.blog_category_path(@category) }
it "should displays categories blog posts" do
+ visit refinery.blog_category_path(@category)
page.should have_content("Refinery CMS blog post")
page.should have_content("Video Games")
end
diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb
index 3422dd2..b6cc7ca 100644
--- a/spec/requests/refinery/blog/posts_spec.rb
+++ b/spec/requests/refinery/blog/posts_spec.rb
@@ -4,45 +4,68 @@ module Refinery
describe "Blog::Posts" do
refinery_login_with :refinery_user
- context "when has blog posts" do
+ context "when has blog posts" do
let!(:blog_post) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") }
-
+
it "should display blog post" do
visit refinery.blog_post_path(blog_post)
-
+
page.should have_content(blog_post.title)
end
-
+
it "should display the blog rss feed" do
get refinery.blog_rss_feed_path
-
+
response.should be_success
response.content_type.should eq("application/rss+xml")
end
+
+ describe "visit blog" do
+
+ before(:each) do
+ Factory.create(:page, :link_url => "/")
+ Factory.create(:page, :link_url => "/blog", :title => "Blog")
+ end
+
+ it "shows blog link in menu" do
+ visit "/"
+ within "#menu" do
+ page.should have_content("Blog")
+ page.should have_selector("a[href='/blog']")
+ end
+ end
+
+ it "shows blog posts" do
+ visit refinery.blog_root_path
+ page.should have_content blog_post.title
+ end
+
+ end
+
end
-
- describe "list tagged posts" do
- context "when has tagged blog posts" do
+
+ describe "list tagged posts" do
+ context "when has tagged blog posts" do
before(:each) do
@tag_name = "chicago"
@post = FactoryGirl.create(:blog_post,
:title => "I Love my city",
:tag_list => @tag_name)
- @tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first
+ @tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first
end
it "should have one tagged post" do
visit refinery.blog_tagged_posts_path(@tag.id, @tag_name.parameterize)
-
+
page.should have_content(@tag_name)
page.should have_content(@post.title)
end
end
end
-
+
describe "#show" do
context "when has no comments" do
let(:blog_post) { FactoryGirl.create(:blog_post) }
-
+
it "should display the blog post" do
visit refinery.blog_post_path(blog_post)
page.should have_content(blog_post.title)
@@ -51,29 +74,29 @@ module Refinery
end
context "when has approved comments" do
let(:approved_comment) { FactoryGirl.create(:approved_comment) }
-
+
it "should display the comments" do
visit refinery.blog_post_path(approved_comment.post)
-
+
page.should have_content(approved_comment.body)
page.should have_content("Posted by #{approved_comment.name}")
end
end
context "when has rejected comments" do
let(:rejected_comment) { FactoryGirl.create(:rejected_comment) }
-
- it "should not display the comments" do
+
+ it "should not display the comments" do
visit refinery.blog_post_path(rejected_comment.post)
-
+
page.should_not have_content(rejected_comment.body)
end
end
context "when has new comments" do
let(:blog_comment) { FactoryGirl.create(:blog_comment) }
-
+
it "should not display the comments" do
visit refinery.blog_post_path(blog_comment.post)
-
+
page.should_not have_content(blog_comment.body)
end
end
@@ -122,16 +145,11 @@ module Refinery
end
context "post recent" do
- let(:blog_post) { FactoryGirl.create(:blog_post) }
- let(:blog_post2) { FactoryGirl.create(:blog_post) }
-
- before do
- visit refinery.blog_post_path(blog_post2)
- visit refinery.blog_post_path(blog_post)
- end
+ let!(:blog_post) { FactoryGirl.create(:blog_post, :published_at => Time.now - 5.minutes) }
+ let!(:blog_post2) { FactoryGirl.create(:blog_post, :published_at => Time.now - 2.minutes) }
it "should be the most recent" do
- Refinery::Blog::Post.recent(2).first.should eq(blog_post2)
+ Refinery::Blog::Post.recent(2).first.id.should eq(blog_post2.id)
end
end
@@ -139,19 +157,19 @@ module Refinery
describe "#show draft preview" do
let(:blog_post) { FactoryGirl.create(:blog_post_draft) }
- context "when logged in as admin" do
+ context "when logged in as admin" do
it "should display the draft notification" do
visit refinery.blog_post_path(blog_post)
-
+
page.should have_content('This page is NOT live for public viewing.')
end
end
context "when not logged in as an admin" do
before(:each) { visit refinery.destroy_refinery_user_session_path }
-
+
it "should not display the blog post" do
visit refinery.blog_post_path(blog_post)
-
+
page.should have_content("The page you were looking for doesn't exist (404)")
end
end