spec/features/refinery/blog/admin/posts_spec.rb in refinerycms-blog-3.0.2 vs spec/features/refinery/blog/admin/posts_spec.rb in refinerycms-blog-4.0.0
- old
+ new
@@ -1,16 +1,29 @@
# encoding: utf-8
require "spec_helper"
+shared_context "with_user_class" do
+ # This context changes the user class and updates the author association on Post.
+ before :each do
+ @old_user_class = Refinery::Blog.user_class
+ allow(Refinery::Blog).to receive(:user_class).and_return(Refinery::Blog::TestUser)
+ Refinery::Blog::Post.reflections['author'].instance_variable_set(:@class_name, Refinery::Blog.user_class.to_s)
+ end
+
+ after :each do
+ Refinery::Blog::Post.reflections['author'].instance_variable_set(:@class_name, @old_user_class.to_s)
+ end
+end
+
module Refinery
module Blog
module Admin
describe Post, type: :feature do
- refinery_login_with_devise :authentication_devise_refinery_superuser
+ refinery_login
let!(:blog_category) do
- Globalize.with_locale(:en) { FactoryGirl.create(:blog_category) }
+ Globalize.with_locale(:en) { FactoryBot.create(:blog_category) }
end
context "when no blog posts" do
before { subject.class.destroy_all }
@@ -37,12 +50,13 @@
end
describe "create blog post" do
before do
expect(subject.class.count).to eq(0)
- fill_in "post_title", :with => "This is my blog post"
+ fill_in "post_title", with: "This is my blog post"
fill_in "post_body", with: "<p>And I love it</p>"
+ fill_in "post_user_id", with: "John Doe"
expect(page).to have_css '.blog_categories'
expect(page).to have_css "#post_category_ids_#{blog_category.id}"
expect { check(blog_category.title) }.to change {
!!page.find("#post_category_ids_#{blog_category.id}").checked?
@@ -55,26 +69,23 @@
it "should be the only blog post" do
expect(subject.class.count).to eq(1)
end
- it "should belong to me" do
- expect(subject.class.first.author).to eq(::Refinery::Blog.user_class.last)
- end
-
it "should save categories" do
expect(subject.class.last.categories.count).to eq(1)
expect(subject.class.last.categories.first.title).to eq(blog_category.title)
end
end
describe "create blog post with tags" do
let(:tag_list) { "chicago, bikes, beers, babes" }
before do
- fill_in "Title", :with => "This is a tagged blog post"
+ fill_in "Title", with: "This is a tagged blog post"
fill_in "post_body", with: "<p>And I also love it</p>"
- fill_in "Tags", :with => tag_list
+ fill_in "post_user_id", with: "John Doe"
+ fill_in "Tags", with: tag_list
click_button "Save"
end
it "should succeed" do
expect(page).to have_content("was successfully added.")
@@ -91,11 +102,11 @@
end
end
context "when has blog posts" do
let!(:blog_post) do
- Globalize.with_locale(:en) { FactoryGirl.create(:blog_post) }
+ Globalize.with_locale(:en) { FactoryBot.create(:blog_post) }
end
describe "blog post listing" do
before { visit refinery.blog_admin_posts_path }
@@ -151,22 +162,24 @@
end
end
end
context "with multiple users" do
- let!(:other_guy) { FactoryGirl.create(:authentication_devise_refinery_user, :username => "Other Guy") }
+ include_context "with_user_class"
+ let!(:other_guy) { FactoryBot.create(:blog_test_user, :username => "Other Guy") }
+
describe "create blog post with alternate author" 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"
fill_in "post_body", with: "<p>I totally did not write it.</p>"
expect(page).to have_content("Author")
- select other_guy.username, :from => "Author"
+ select other_guy.username, from: "Author"
click_button "Save"
expect(page).to have_content("was successfully added.")
end
@@ -178,23 +191,24 @@
context "with translations" do
before do
Globalize.locale = :en
allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
- blog_page = FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog")
+ blog_page = FactoryBot.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"
+ fill_in "Title", with: "Post"
+ fill_in "post_body", with: "One post in my blog"
+ fill_in "post_user_id", with: "John Doe"
click_button "Save"
@p = Refinery::Blog::Post.by_title("Post")
end
it "succeeds" do
@@ -235,12 +249,13 @@
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"
+ fill_in "Title", with: ru_page_title
+ fill_in "post_body", with: "One post in my blog"
+ fill_in "post_user_id", with: "John Doe"
click_button "Save"
@p = Refinery::Blog::Post.by_title(ru_page_title)
end
it "succeeds" do
@@ -280,11 +295,11 @@
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') }
+ _blog_post = Globalize.with_locale(:en) { FactoryBot.create(:blog_post, :title => 'First Post') }
Globalize.with_locale(:ru) do
_blog_post.title = 'Домашняя страница'
_blog_post.save
end
_blog_post
@@ -323,11 +338,10 @@
end
fill_in "Title", :with => "Нов"
click_button "Save"
- expect(page).not_to have_content(blog_post.title)
expect(page).to have_content("'Нов' was successfully updated.")
end
end
describe "delete the post translation in secondary locale" do
@@ -336,10 +350,10 @@
click_link("RU")
end
click_link "Remove this translation"
- expect(page).not_to have_content(blog_post.title)
+ expect(page).not_to have_content('RU')
expect(page).to have_content("The translation was successfully removed.")
end
end
end
end