From 7a76219d721d6e07a8b99dd3bbcfb87136d05052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Thu, 27 Jun 2013 09:25:19 +0300 Subject: Update specs due to recent Capybara/FactoryGirl upgrade. --- spec/factories/blog_posts.rb | 4 +- .../refinery/blog/admin/categories_spec.rb | 119 ++++++++ spec/features/refinery/blog/admin/comments_spec.rb | 121 ++++++++ spec/features/refinery/blog/admin/menu_spec.rb | 13 + spec/features/refinery/blog/admin/posts_spec.rb | 338 +++++++++++++++++++++ spec/features/refinery/blog/categories_spec.rb | 28 ++ spec/features/refinery/blog/posts_spec.rb | 180 +++++++++++ spec/models/refinery/blog/post_spec.rb | 6 +- .../refinery/blog/admin/categories_spec.rb | 119 -------- spec/requests/refinery/blog/admin/comments_spec.rb | 121 -------- spec/requests/refinery/blog/admin/menu_spec.rb | 13 - spec/requests/refinery/blog/admin/posts_spec.rb | 328 -------------------- spec/requests/refinery/blog/categories_spec.rb | 28 -- spec/requests/refinery/blog/posts_spec.rb | 185 ----------- 14 files changed, 804 insertions(+), 799 deletions(-) create mode 100644 spec/features/refinery/blog/admin/categories_spec.rb create mode 100644 spec/features/refinery/blog/admin/comments_spec.rb create mode 100644 spec/features/refinery/blog/admin/menu_spec.rb create mode 100644 spec/features/refinery/blog/admin/posts_spec.rb create mode 100644 spec/features/refinery/blog/categories_spec.rb create mode 100644 spec/features/refinery/blog/posts_spec.rb delete mode 100644 spec/requests/refinery/blog/admin/categories_spec.rb delete mode 100644 spec/requests/refinery/blog/admin/comments_spec.rb delete mode 100644 spec/requests/refinery/blog/admin/menu_spec.rb delete mode 100644 spec/requests/refinery/blog/admin/posts_spec.rb delete mode 100644 spec/requests/refinery/blog/categories_spec.rb delete mode 100644 spec/requests/refinery/blog/posts_spec.rb (limited to 'spec') diff --git a/spec/factories/blog_posts.rb b/spec/factories/blog_posts.rb index eebad3c..ff4cf16 100644 --- a/spec/factories/blog_posts.rb +++ b/spec/factories/blog_posts.rb @@ -5,8 +5,8 @@ FactoryGirl.define do draft false tag_list "chicago, shopping, fun times" published_at Time.now - author { Factory(:refinery_user) } - + author { FactoryGirl.create(:refinery_user) } + factory :blog_post_draft do draft true end diff --git a/spec/features/refinery/blog/admin/categories_spec.rb b/spec/features/refinery/blog/admin/categories_spec.rb new file mode 100644 index 0000000..f3cdc5a --- /dev/null +++ b/spec/features/refinery/blog/admin/categories_spec.rb @@ -0,0 +1,119 @@ +# encoding: utf-8 +require 'spec_helper' + +describe "Categories admin" do + refinery_login_with :refinery_user + + let(:title) { "lol" } + + it "can create categories" do + visit refinery.admin_root_path + + within("nav#menu") { click_link "Blog" } + within("nav.multilist") { click_link "Create new category" } + + fill_in "Title", :with => title + click_button "Save" + + category = Refinery::Blog::Category.first + category.title.should eq(title) + end + + context "with translations" do + before do + Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru]) + blog_page = Globalize.with_locale(:en) { FactoryGirl.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/features/refinery/blog/admin/comments_spec.rb b/spec/features/refinery/blog/admin/comments_spec.rb new file mode 100644 index 0000000..08fe9df --- /dev/null +++ b/spec/features/refinery/blog/admin/comments_spec.rb @@ -0,0 +1,121 @@ +require "spec_helper" + +module Refinery + module Blog + module Admin + describe Comment do + refinery_login_with :refinery_user + + describe "#index" do + context "when has no new unapproved comments" do + before do + subject.class.delete_all + visit refinery.blog_admin_comments_path + end + + it "should list no comments" do + visit refinery.blog_admin_comments_path + + page.should have_content('There are no new comments') + end + end + context "when has new unapproved comments" do + let!(:blog_comment) { FactoryGirl.create(:blog_comment) } + before { visit refinery.blog_admin_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to approve a comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + + it "should allow me to reject a comment" do + click_link "Reject this comment" + + page.should have_content("has been rejected") + end + end + end + + describe "#approved" do + context "when has no approved comments" do + before do + subject.class.delete_all + visit refinery.approved_blog_admin_comments_path + end + + it "should list no comments" do + page.should have_content('There are no approved comments') + end + end + context "when has approved comments" do + let!(:blog_comment) do + FactoryGirl.create(:blog_comment, :state => 'approved') + end + before { visit refinery.approved_blog_admin_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to reject a comment" do + click_link "Reject this comment" + + page.should have_content("has been rejected") + end + end + end + + describe "#rejected" do + context "when has no rejected comments" do + before do + subject.class.delete_all + visit refinery.rejected_blog_admin_comments_path + end + + it "should list no comments" do + page.should have_content('There are no rejected comments') + end + end + context "when has rejected comments" do + let!(:blog_comment) do + FactoryGirl.create(:blog_comment, :state => 'rejected') + end + before { visit refinery.rejected_blog_admin_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to approve a comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + end + end + + describe "#show" do + let!(:blog_comment) { FactoryGirl.create(:blog_comment) } + before { visit refinery.blog_admin_comment_path(blog_comment) } + it "should display the comment" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + it "should allow me to approve the comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + end + end + end + end +end diff --git a/spec/features/refinery/blog/admin/menu_spec.rb b/spec/features/refinery/blog/admin/menu_spec.rb new file mode 100644 index 0000000..ba10ffe --- /dev/null +++ b/spec/features/refinery/blog/admin/menu_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe "Blog menu entry" do + refinery_login_with :refinery_user + + it "is highlighted when managing the blog" do + visit refinery.admin_root_path + + within("#menu") { click_link "Blog" } + + page.should have_css("a.active", :text => "Blog") + end +end diff --git a/spec/features/refinery/blog/admin/posts_spec.rb b/spec/features/refinery/blog/admin/posts_spec.rb new file mode 100644 index 0000000..a5d4f62 --- /dev/null +++ b/spec/features/refinery/blog/admin/posts_spec.rb @@ -0,0 +1,338 @@ +# encoding: utf-8 +require "spec_helper" + +module Refinery + module Blog + module Admin + describe Post do + refinery_login_with :refinery_user + + let!(:blog_category) do + Globalize.with_locale(:en) { FactoryGirl.create(:blog_category) } + end + + context "when no blog posts" do + before { subject.class.destroy_all } + + describe "blog post listing" do + before { visit refinery.blog_admin_posts_path } + + it "invites to create new post" do + page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.") + end + end + + describe "new blog post form" do + before do + visit refinery.blog_admin_posts_path + click_link "Create new post" + end + + it "should have Tags" do + page.should have_content("Tags") + end + + it "should have category title", :js => true do + click_link "toggle_advanced_options" + page.should have_content(blog_category.title) + end + + describe "create blog post", :js => true do + before do + fill_in "post_title", :with => "This is my blog post" + # this is a dirty hack but textarea that needs to be filled is + # hidden and capybara refuses to fill in elements it can't see + page.evaluate_script("WYMeditor.INSTANCES[0].html('

And I love it

')") + click_link "toggle_advanced_options" + check blog_category.title + click_button "Save" + end + + it "should succeed" do + page.should have_content("was successfully added.") + end + + it "should be the only blog post" do + subject.class.count.should eq(1) + end + + it "should belong to me" do + subject.class.first.author.should eq(::Refinery::User.last) + end + + it "should save categories" do + subject.class.last.categories.count.should eq(1) + subject.class.last.categories.first.title.should eq(blog_category.title) + end + end + + describe "create blog post with tags", :js => true do + before do + @tag_list = "chicago, bikes, beers, babes" + fill_in "Title", :with => "This is a tagged blog post" + # this is a dirty hack but textarea that needs to be filled is + # hidden and capybara refuses to fill in elements it can't see + page.evaluate_script("WYMeditor.INSTANCES[0].html('

And I also love it

')") + fill_in "Tags", :with => @tag_list + click_button "Save" + end + + it "should succeed" do + page.should have_content("was successfully added.") + end + + it "should be the only blog post" do + subject.class.count.should eq(1) + end + + it "should have the specified tags" do + subject.class.last.tag_list.sort.should eq(@tag_list.split(', ').sort) + end + end + end + end + + context "when has blog posts" do + let!(:blog_post) do + Globalize.with_locale(:en) { FactoryGirl.create(:blog_post) } + end + + describe "blog post listing" do + before { visit refinery.blog_admin_posts_path } + + describe "edit blog post" do + it "should succeed" do + page.should have_content(blog_post.title) + + click_link("Edit this blog post") + current_path.should == refinery.edit_blog_admin_post_path(blog_post) + + fill_in "post_title", :with => "hax0r" + click_button "Save" + + page.should_not have_content(blog_post.title) + page.should have_content("'hax0r' was successfully updated.") + end + end + + describe "deleting blog post" do + it "should succeed" do + page.should have_content(blog_post.title) + + click_link "Remove this blog post forever" + + page.should have_content("'#{blog_post.title}' was successfully removed.") + end + end + + describe "view live" do + it "redirects to blog post in the frontend" do + click_link "View this blog post live" + + current_path.should == refinery.blog_post_path(blog_post) + page.should have_content(blog_post.title) + end + end + end + + context "when uncategorized post" do + it "shows up in the list" do + visit refinery.uncategorized_blog_admin_posts_path + page.should have_content(blog_post.title) + end + end + + context "when categorized post" do + it "won't show up in the list" do + blog_post.categories << blog_category + blog_post.save! + + visit refinery.uncategorized_blog_admin_posts_path + page.should_not have_content(blog_post.title) + end + end + end + + context "with multiple users" do + let!(:other_guy) { FactoryGirl.create(:refinery_user, :username => "Other Guy") } + + describe "create blog post with alternate author", :js => true do + before do + visit refinery.blog_admin_posts_path + click_link "Create new post" + + fill_in "post_title", :with => "This is some other guy's blog post" + # this is a dpage_titleirty hack but textarea that needs to be filled is + # hidden and capybara refuses to fill in elements it can't see + page.evaluate_script("WYMeditor.INSTANCES[0].html('

I totally did not write it.

')") + + click_link "toggle_advanced_options" + + select other_guy.username, :from => "Author" + + click_button "Save" + end + + it "should succeed" do + page.should have_content("was successfully added.") + end + + it "belongs to another user" do + subject.class.last.author.should eq(other_guy) + end + end + end + + context "with translations" do + before do + Globalize.locale = :en + Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru]) + blog_page = FactoryGirl.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 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 +end diff --git a/spec/features/refinery/blog/categories_spec.rb b/spec/features/refinery/blog/categories_spec.rb new file mode 100644 index 0000000..021dd94 --- /dev/null +++ b/spec/features/refinery/blog/categories_spec.rb @@ -0,0 +1,28 @@ +require "spec_helper" + +module Refinery + describe "BlogCategories" do + refinery_login_with :refinery_user + + context "has one category and post" do + before do + 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 + 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 + end + end + end +end diff --git a/spec/features/refinery/blog/posts_spec.rb b/spec/features/refinery/blog/posts_spec.rb new file mode 100644 index 0000000..1fe56bc --- /dev/null +++ b/spec/features/refinery/blog/posts_spec.rb @@ -0,0 +1,180 @@ +require "spec_helper" + +module Refinery + describe "Blog::Posts" do + refinery_login_with :refinery_user + + context "when has blog posts" do + let!(:blog_post) do + Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") } + end + + it "should display blog post" do + visit refinery.blog_post_path(blog_post) + + page.should have_content(blog_post.title) + end + + describe "visit blog" do + + before do + FactoryGirl.create(:page, :link_url => "/") + FactoryGirl.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 + before 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 + 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) + page.should have_content(blog_post.body) + end + 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 + 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 + + context "when posting comments" do + let(:blog_post) { FactoryGirl.create(:blog_post) } + let(:name) { "pete" } + let(:email) { "pete@mcawesome.com" } + let(:body) { "Witty comment." } + + before do + visit refinery.blog_post_path(blog_post) + + fill_in "Name", :with => name + fill_in "Email", :with => email + fill_in "Message", :with => body + click_button "Send comment" + end + + it "creates the comment" do + comment = blog_post.reload.comments.last + + comment.name.should eq(name) + comment.email.should eq(email) + comment.body.should eq(body) + end + end + + context "post popular" do + let(:blog_post) { FactoryGirl.create(:blog_post) } + let(:blog_post2) { FactoryGirl.create(:blog_post) } + + before do + visit refinery.blog_post_path(blog_post) + end + + it "should increment access count" do + blog_post.reload.access_count.should eq(1) + visit refinery.blog_post_path(blog_post) + blog_post.reload.access_count.should eq(2) + end + + it "should be most popular" do + Refinery::Blog::Post.popular(2).first.should eq(blog_post) + end + end + + context "post recent" do + 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.id.should eq(blog_post2.id) + end + end + + end + + describe "#show draft preview" do + let(:blog_post) { FactoryGirl.create(:blog_post_draft) } + + 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 do + # TODO: remove Refinery::Pages::Engine.load_seed dependency. + # It's here to temporary fix the issue with 404 after visiting logout path. + Refinery::Pages::Engine.load_seed + visit refinery.logout_path + end + + it "should not display the blog post" do + visit refinery.blog_post_path(blog_post) + + page.should have_content("The page you requested was not found.") + end + end + end + end +end diff --git a/spec/models/refinery/blog/post_spec.rb b/spec/models/refinery/blog/post_spec.rb index 84e9c87..cec6a2f 100644 --- a/spec/models/refinery/blog/post_spec.rb +++ b/spec/models/refinery/blog/post_spec.rb @@ -114,15 +114,15 @@ module Refinery describe "#live?" do it "returns true if post is not in draft and it's published" do - Factory.build(:blog_post).should be_live + FactoryGirl.build(:blog_post).should be_live end it "returns false if post is in draft" do - Factory.build(:blog_post, :draft => true).should_not be_live + FactoryGirl.build(:blog_post, :draft => true).should_not be_live end it "returns false if post pub date is in future" do - Factory.build(:blog_post, :published_at => Time.now.advance(:minutes => 1)).should_not be_live + FactoryGirl.build(:blog_post, :published_at => Time.now.advance(:minutes => 1)).should_not be_live end end diff --git a/spec/requests/refinery/blog/admin/categories_spec.rb b/spec/requests/refinery/blog/admin/categories_spec.rb deleted file mode 100644 index 9d4ddf3..0000000 --- a/spec/requests/refinery/blog/admin/categories_spec.rb +++ /dev/null @@ -1,119 +0,0 @@ -# encoding: utf-8 -require 'spec_helper' - -describe "Categories admin" do - refinery_login_with :refinery_user - - let(:title) { "lol" } - - it "can create categories" do - visit refinery.admin_root_path - - within("nav#menu") { click_link "Blog" } - within("nav.multilist") { click_link "Create new category" } - - fill_in "Title", :with => title - click_button "Save" - - 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/comments_spec.rb b/spec/requests/refinery/blog/admin/comments_spec.rb deleted file mode 100644 index c834d13..0000000 --- a/spec/requests/refinery/blog/admin/comments_spec.rb +++ /dev/null @@ -1,121 +0,0 @@ -require "spec_helper" - -module Refinery - module Blog - module Admin - describe Comment do - refinery_login_with :refinery_user - - describe "#index" do - context "when has no new unapproved comments" do - before(:each) do - subject.class.delete_all - visit refinery.blog_admin_comments_path - end - - it "should list no comments" do - visit refinery.blog_admin_comments_path - - page.should have_content('There are no new comments') - end - end - context "when has new unapproved comments" do - let!(:blog_comment) { FactoryGirl.create(:blog_comment) } - before(:each) { visit refinery.blog_admin_comments_path } - - it "should list comments" do - page.should have_content(blog_comment.body) - page.should have_content(blog_comment.name) - end - - it "should allow me to approve a comment" do - click_link "Approve this comment" - - page.should have_content("has been approved") - end - - it "should allow me to reject a comment" do - click_link "Reject this comment" - - page.should have_content("has been rejected") - end - end - end - - describe "#approved" do - context "when has no approved comments" do - before(:each) do - subject.class.delete_all - visit refinery.approved_blog_admin_comments_path - end - - it "should list no comments" do - page.should have_content('There are no approved comments') - end - end - context "when has approved comments" do - let!(:blog_comment) do - FactoryGirl.create(:blog_comment, :state => 'approved') - end - before(:each) { visit refinery.approved_blog_admin_comments_path } - - it "should list comments" do - page.should have_content(blog_comment.body) - page.should have_content(blog_comment.name) - end - - it "should allow me to reject a comment" do - click_link "Reject this comment" - - page.should have_content("has been rejected") - end - end - end - - describe "#rejected" do - context "when has no rejected comments" do - before(:each) do - subject.class.delete_all - visit refinery.rejected_blog_admin_comments_path - end - - it "should list no comments" do - page.should have_content('There are no rejected comments') - end - end - context "when has rejected comments" do - let!(:blog_comment) do - FactoryGirl.create(:blog_comment, :state => 'rejected') - end - before(:each) { visit refinery.rejected_blog_admin_comments_path } - - it "should list comments" do - page.should have_content(blog_comment.body) - page.should have_content(blog_comment.name) - end - - it "should allow me to approve a comment" do - click_link "Approve this comment" - - page.should have_content("has been approved") - end - end - end - - describe "#show" do - let!(:blog_comment) { FactoryGirl.create(:blog_comment) } - before(:each) { visit refinery.blog_admin_comment_path(blog_comment) } - it "should display the comment" do - page.should have_content(blog_comment.body) - page.should have_content(blog_comment.name) - end - it "should allow me to approve the comment" do - click_link "Approve this comment" - - page.should have_content("has been approved") - end - end - end - end - end -end diff --git a/spec/requests/refinery/blog/admin/menu_spec.rb b/spec/requests/refinery/blog/admin/menu_spec.rb deleted file mode 100644 index ba10ffe..0000000 --- a/spec/requests/refinery/blog/admin/menu_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe "Blog menu entry" do - refinery_login_with :refinery_user - - it "is highlighted when managing the blog" do - visit refinery.admin_root_path - - within("#menu") { click_link "Blog" } - - page.should have_css("a.active", :text => "Blog") - end -end diff --git a/spec/requests/refinery/blog/admin/posts_spec.rb b/spec/requests/refinery/blog/admin/posts_spec.rb deleted file mode 100644 index 0b3890a..0000000 --- a/spec/requests/refinery/blog/admin/posts_spec.rb +++ /dev/null @@ -1,328 +0,0 @@ -# encoding: utf-8 -require "spec_helper" - -module Refinery - module Blog - 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 - before(:each) { subject.class.destroy_all } - - describe "blog post listing" do - before(:each) { visit refinery.blog_admin_posts_path } - - it "invites to create new post" do - page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.") - end - end - - describe "new blog post form" do - before(:each) do - visit refinery.blog_admin_posts_path - click_link "Create new post" - end - - it "should have Tags" do - page.should have_content("Tags") - end - - it "should have Video Games" do - page.should have_content(blog_category.title) - end - - describe "create blog post" do - before(:each) do - fill_in "Title", :with => "This is my blog post" - fill_in "post_body", :with => "And I love it" - check blog_category.title - click_button "Save" - end - - it "should succeed" do - page.should have_content("was successfully added.") - end - - it "should be the only blog post" do - subject.class.count.should eq(1) - end - - it "should belong to me" do - subject.class.first.author.should eq(::Refinery::User.last) - end - - it "should save categories" do - subject.class.last.categories.count.should eq(1) - subject.class.last.categories.first.title.should eq(blog_category.title) - end - end - - describe "create blog post with tags" do - before(:each) do - @tag_list = "chicago, bikes, beers, babes" - fill_in "Title", :with => "This is a tagged blog post" - fill_in "post_body", :with => "And I also love it" - fill_in "Tags", :with => @tag_list - click_button "Save" - end - - it "should succeed" do - page.should have_content("was successfully added.") - end - - it "should be the only blog post" do - subject.class.count.should eq(1) - end - - it "should have the specified tags" do - subject.class.last.tag_list.sort.should eq(@tag_list.split(', ').sort) - end - end - end - end - - context "when has blog posts" do - 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 } - - describe "edit blog post" do - it "should succeed" do - page.should have_content(blog_post.title) - - click_link("Edit this blog post") - current_path.should == refinery.edit_blog_admin_post_path(blog_post) - - fill_in "Title", :with => "hax0r" - click_button "Save" - - page.should_not have_content(blog_post.title) - page.should have_content("'hax0r' was successfully updated.") - end - end - - describe "deleting blog post" do - it "should succeed" do - page.should have_content(blog_post.title) - - click_link "Remove this blog post forever" - - page.should have_content("'#{blog_post.title}' was successfully removed.") - end - end - - describe "view live" do - it "redirects to blog post in the frontend" do - click_link "View this blog post live" - - current_path.should == refinery.blog_post_path(blog_post) - page.should have_content(blog_post.title) - end - end - end - - context "when uncategorized post" do - it "shows up in the list" do - visit refinery.uncategorized_blog_admin_posts_path - page.should have_content(blog_post.title) - end - end - - context "when categorized post" do - it "won't show up in the list" do - blog_post.categories << blog_category - blog_post.save! - - visit refinery.uncategorized_blog_admin_posts_path - page.should_not have_content(blog_post.title) - end - end - end - - context "with multiple users" do - let!(:other_guy) { Factory(:refinery_user, :username => "Other Guy") } - - describe "create blog post with alternate author" do - before(:each) do - visit refinery.blog_admin_posts_path - click_link "Create new post" - - fill_in "Title", :with => "This is some other guy's blog post" - fill_in "post_body", :with => "I totally didn't write it." - - click_link "Advanced options" - - select other_guy.username, :from => "Author" - - click_button "Save" - end - - it "should succeed" do - page.should have_content("was successfully added.") - end - - it "belongs to another user" do - subject.class.last.author.should eq(other_guy) - 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 -end diff --git a/spec/requests/refinery/blog/categories_spec.rb b/spec/requests/refinery/blog/categories_spec.rb deleted file mode 100644 index ba96b1b..0000000 --- a/spec/requests/refinery/blog/categories_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "spec_helper" - -module Refinery - describe "BlogCategories" do - refinery_login_with :refinery_user - - context "has one category and post" do - before(:each) do - 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 - 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 - end - end - end -end diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb deleted file mode 100644 index 9be8618..0000000 --- a/spec/requests/refinery/blog/posts_spec.rb +++ /dev/null @@ -1,185 +0,0 @@ -require "spec_helper" - -module Refinery - describe "Blog::Posts" do - refinery_login_with :refinery_user - - context "when has blog posts" do - let!(:blog_post) { Globalize.with_locale(:en) { 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 - 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 - 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) - page.should have_content(blog_post.body) - end - 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 - 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 - - context "when posting comments" do - let(:blog_post) { Factory(:blog_post) } - let(:name) { "pete" } - let(:email) { "pete@mcawesome.com" } - let(:body) { "Witty comment." } - - before do - visit refinery.blog_post_path(blog_post) - - fill_in "Name", :with => name - fill_in "Email", :with => email - fill_in "Message", :with => body - click_button "Send comment" - end - - it "creates the comment" do - comment = blog_post.reload.comments.last - - comment.name.should eq(name) - comment.email.should eq(email) - comment.body.should eq(body) - end - end - - context "post popular" do - let(:blog_post) { FactoryGirl.create(:blog_post) } - let(:blog_post2) { FactoryGirl.create(:blog_post) } - - before do - visit refinery.blog_post_path(blog_post) - end - - it "should increment access count" do - blog_post.reload.access_count.should eq(1) - visit refinery.blog_post_path(blog_post) - blog_post.reload.access_count.should eq(2) - end - - it "should be most popular" do - Refinery::Blog::Post.popular(2).first.should eq(blog_post) - end - end - - context "post recent" do - 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.id.should eq(blog_post2.id) - end - end - - end - - describe "#show draft preview" do - let(:blog_post) { FactoryGirl.create(:blog_post_draft) } - - 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 do - # TODO: remove Refinery::Pages::Engine.load_seed dependency. - # It's here to temporary fix the issue with 404 after visiting logout path. - Refinery::Pages::Engine.load_seed - visit refinery.logout_path - end - - it "should not display the blog post" do - visit refinery.blog_post_path(blog_post) - - page.should have_content("The page you requested was not found.") - end - end - end - end -end -- cgit v1.2.3