diff options
22 files changed, 371 insertions, 307 deletions
diff --git a/.travis.yml b/.travis.yml index 1dbb9b9..5b184d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,16 @@ language: ruby -sudo: false cache: bundler bundler_args: --without development -before_script: - - "sh -e /etc/init.d/xvfb start" - - "bundle exec rake refinery:testing:dummy_app" -script: - - "DISPLAY=:99.0 bundle exec rspec spec" -notifications: - email: true - irc: - use_notice: true - skip_join: true - channels: - - "irc.freenode.org#refinerycms" - campfire: - on_success: always - on_failure: always - rooms: - - secure: "JaX+Ckvdd2wqL2bD6t8PHvMDBHxWBlCrkBKPcDKxV0t0DOwzzzwxMryVqcRi\nPsmM/zvmWFATDyRmivhNOpu4lRg9RytSroxZ9nkmbLDqjCyEAZ6tv4yZXME/\nPaxPwmfwgS9g8TKjj3lSWS7rEpqqg0D5S0XIfIHrj6KB6LUmFHc=" - webhooks: - - https://webhooks.gitter.im/e/b5d48907cdc89864b874 +before_script: "bundle exec rake refinery:testing:dummy_app" env: - DB=postgresql - DB=mysql +notifications: + webhooks: + - https://webhooks.gitter.im/e/b5d48907cdc89864b874 rvm: + - 2.3.1 - 2.2 - 2.1 + - 2.0.0 +sudo: false
\ No newline at end of file @@ -1,5 +1,7 @@ source "https://rubygems.org" +gem "refinerycms-authentication-devise", '~> 1.0.4' + gemspec git "https://github.com/refinery/refinerycms", branch: "master" do diff --git a/app/controllers/refinery/blog/admin/categories_controller.rb b/app/controllers/refinery/blog/admin/categories_controller.rb index e9f2f89..2176484 100644 --- a/app/controllers/refinery/blog/admin/categories_controller.rb +++ b/app/controllers/refinery/blog/admin/categories_controller.rb @@ -4,6 +4,7 @@ module Refinery class CategoriesController < ::Refinery::AdminController crudify :'refinery/blog/category', + :include => [:translations], :order => 'title ASC' private diff --git a/app/controllers/refinery/blog/admin/posts_controller.rb b/app/controllers/refinery/blog/admin/posts_controller.rb index 61ac433..aeb3c43 100644 --- a/app/controllers/refinery/blog/admin/posts_controller.rb +++ b/app/controllers/refinery/blog/admin/posts_controller.rb @@ -85,9 +85,15 @@ module Refinery private def post_params - params.require(:post).permit(:title, :body, :custom_teaser, :tag_list, + params.require(:post).permit(permitted_post_params) + end + + def permitted_post_params + [ + :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url, :user_id, :browser_title, - :meta_description, :source_url, :source_url_title, :category_ids => []) + :meta_description, :source_url, :source_url_title, :category_ids => [] + ] end protected diff --git a/app/helpers/refinery/blog/controller_helper.rb b/app/helpers/refinery/blog/controller_helper.rb index 7235096..1c0491b 100644 --- a/app/helpers/refinery/blog/controller_helper.rb +++ b/app/helpers/refinery/blog/controller_helper.rb @@ -6,7 +6,7 @@ module Refinery def find_blog_post unless (@post = Refinery::Blog::Post.with_globalize.friendly.find(params[:id])).try(:live?) - if refinery_user? and current_refinery_user.authorized_plugins.include?("refinerycms_blog") + if current_refinery_user && current_refinery_user.has_plugin?("refinerycms_blog") @post = Refinery::Blog::Post.friendly.find(params[:id]) else error_404 diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb index d05cb14..9e69162 100644 --- a/app/models/refinery/blog/post.rb +++ b/app/models/refinery/blog/post.rb @@ -21,7 +21,8 @@ module Refinery validates :title, :presence => true, :uniqueness => true validates :body, :presence => true - validates :published_at, :author, :presence => true + validates :published_at, :presence => true + validates :author, :presence => true, if: :author_required? validates :source_url, :url => { :if => 'Refinery::Blog.validate_source_url', :update => true, :allow_nil => true, @@ -31,6 +32,11 @@ module Refinery class Translation is_seo_meta end + + # Override this to disable required authors + def author_required? + true + end # If custom_url or title changes tell friendly_id to regenerate slug when # saving record diff --git a/app/views/refinery/blog/posts/index.html.erb b/app/views/refinery/blog/posts/index.html.erb index 772f2ec..3a386f9 100644 --- a/app/views/refinery/blog/posts/index.html.erb +++ b/app/views/refinery/blog/posts/index.html.erb @@ -1,5 +1,5 @@ <% content_for :body do %> - <%= raw @page.content_for(Refinery::Pages.default_parts.first.to_sym) if Refinery::Pages.default_parts.any? %> + <%= raw @page.content_for(Refinery::Pages.default_parts.first[:slug].to_sym) if Refinery::Pages.default_parts.any? %> <% if @posts.any? %> <section id="blog_posts"> @@ -12,7 +12,7 @@ <% end %> <% content_for :side_body_prepend do -%> - <%= raw @page.content_for(Refinery::Pages.default_parts.second.to_sym) %> + <%= raw @page.content_for(Refinery::Pages.default_parts.second[:slug].to_sym) %> <% end if Refinery::Pages.default_parts.many? -%> <%= render '/refinery/blog/shared/body_content_right' %> diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 839e03b..d17dc00 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -38,13 +38,15 @@ ru: toggle_advanced_options: 'Нажмите, чтобы получить доступ к настройкам мета-тегов и меню' published_at: Дата публикации custom_url: Переадресовывать на другой сайт или страницу - custom_url_help: Переадресовывать на другой сайт или страницу. - source_url: Источник - source_url_help: Источник сообщения. + custom_url_help: "Ссылка будет взята из данного поля, вместо генерации из названия записи." + source_url: URL источника + source_url_help: Источник материала данной записи. source_url_title: Название источника сообщения source_url_title_help: Название источника сообщения в посте. - author: Author - author_help: Установить, какой пользователь написал данное сообщение, покажет как автора. + author: Автор + author_help: 'Установить, какой пользователь будет покажан как автор записи.' + copy_body: Копировать основное сообщение в краткое + copy_body_help: 'Копирует основное сообщение в краткое. Оставьте краткое сообщение пустым, чтобы Refinery составлял его автоматически.' index: no_items_yet: 'Записи в блоге отстутствуют. Нажмите "%{create}", чтобы добавить первую запись.' uncategorized: @@ -53,6 +55,10 @@ ru: view_live_html: Посмотреть запись на сайте <br/><em>(откроется в новом окне)</em> edit: Редактировать запись delete: Удалить запись + delete_translation: Удалить этот перевод + delete_translation_confirmation: Вы действительно хотите навсегда удалить этот перевод? + delete_translation_success: Перевод был успешно удален. + draft: Черновик settings: notification_recipients: value: Отправлять уведомления @@ -82,6 +88,7 @@ ru: moderation: Модерирование update_notified: Настроить уведомления comments: Комментарии + teasers: Краткие содержания comment_mailer: notification: greeting: Здравствуйте @@ -91,6 +98,10 @@ ru: from: От email: Эл. почта message: Сообщение + approve: Подтвердите + or: " или " + reject: отклоните + this_comment: " этот комментарий." closing_line: С уважением ps: P.S. Все комментарии находятся в разделе "Блог" Refinery CMS в подменю "Комментарии". shared: @@ -130,7 +141,6 @@ ru: add: Написать комментарий other: Другие записи filled_in: Категория - submit: Отправить комментарий tagged: Тэги submit: Отправить коментарий name: Имя @@ -138,6 +148,9 @@ ru: message: Сообщение by: Автор source: Источник + tagged: + no_blog_articles_yet: Пока ни одной записи не опубликовано. Следите за новостями. + posts_tagged: Записи с тегом archive: blog_archive_for: 'Архив %{date}' no_blog_articles_posted: 'Ни одной записи за %{date} не опубликовано. Следите за новостями.' diff --git a/lib/refinery/blog/configuration.rb b/lib/refinery/blog/configuration.rb index 6198cb2..9b4b5dc 100644 --- a/lib/refinery/blog/configuration.rb +++ b/lib/refinery/blog/configuration.rb @@ -26,7 +26,7 @@ module Refinery end def user_class - class_name = @@user_class_name || 'Refinery::User' + class_name = @@user_class_name || "Refinery::Authentication::Devise::User" begin Object.const_get(class_name) rescue NameError diff --git a/lib/refinery/blog/engine.rb b/lib/refinery/blog/engine.rb index cc0d59a..e0cba6f 100644 --- a/lib/refinery/blog/engine.rb +++ b/lib/refinery/blog/engine.rb @@ -15,6 +15,7 @@ module Refinery Rails.application.config.assets.precompile += %w( refinery/blog/backend.css + refinery/blog/frontend.css refinery/blog/**/*.css ) end diff --git a/refinerycms-blog.gemspec b/refinerycms-blog.gemspec index af5ac10..acd0bab 100644 --- a/refinerycms-blog.gemspec +++ b/refinerycms-blog.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = %q{refinerycms-blog} - s.version = %q{3.0.0} + s.version = %q{3.0.1} s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with Refinery CMS.} s.summary = %q{Ruby on Rails blogging engine for Refinery CMS.} s.email = %q{info@refinerycms.com} diff --git a/spec/controllers/refinery/blog/admin/comments_controller_spec.rb b/spec/controllers/refinery/blog/admin/comments_controller_spec.rb index 4139c18..0816188 100644 --- a/spec/controllers/refinery/blog/admin/comments_controller_spec.rb +++ b/spec/controllers/refinery/blog/admin/comments_controller_spec.rb @@ -4,7 +4,8 @@ module Refinery module Blog module Admin describe CommentsController, type: :controller do - refinery_login_with :refinery_user + refinery_login_with_devise [:refinery, :superuser] + before do logged_in_user.plugins = logged_in_user.plugins | %w(refinerycms_blog) end diff --git a/spec/controllers/refinery/blog/admin/posts_controller_spec.rb b/spec/controllers/refinery/blog/admin/posts_controller_spec.rb index 3ff04b4..65df5b3 100644 --- a/spec/controllers/refinery/blog/admin/posts_controller_spec.rb +++ b/spec/controllers/refinery/blog/admin/posts_controller_spec.rb @@ -4,7 +4,7 @@ module Refinery module Blog module Admin describe PostsController, type: :controller do - refinery_login_with [:refinery, :superuser] + refinery_login_with_devise [:refinery, :superuser] describe "#delete_translation" do let!(:blog_post) { FactoryGirl.create(:blog_post) } diff --git a/spec/factories/blog_posts.rb b/spec/factories/blog_posts.rb index 51c6b8a..9b88b46 100644 --- a/spec/factories/blog_posts.rb +++ b/spec/factories/blog_posts.rb @@ -4,7 +4,7 @@ FactoryGirl.define do body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it." draft false published_at Time.now - author { FactoryGirl.create(:refinery_user) } + author { FactoryGirl.create(:authentication_devise_refinery_user) } factory :blog_post_draft do draft true diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 0000000..0112b25 --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,27 @@ +FactoryGirl.define do + factory :authentication_devise_user, :class => Refinery::Authentication::Devise::User do + sequence(:username) { |n| "refinery#{n}" } + sequence(:email) { |n| "refinery#{n}@example.com" } + password "refinerycms" + password_confirmation "refinerycms" + end + + factory :authentication_devise_refinery_user, :parent => :authentication_devise_user do + roles { [ ::Refinery::Authentication::Devise::Role[:refinery] ] } + + after(:create) do |user| + ::Refinery::Plugins.registered.each_with_index do |plugin, index| + user.plugins.create(:name => plugin.name, :position => index) + end + end + end + + factory :authentication_devise_refinery_superuser, :parent => :authentication_devise_refinery_user do + roles { + [ + ::Refinery::Authentication::Devise::Role[:refinery], + ::Refinery::Authentication::Devise::Role[:superuser] + ] + } + end +end
\ No newline at end of file diff --git a/spec/features/refinery/blog/admin/categories_spec.rb b/spec/features/refinery/blog/admin/categories_spec.rb index 7a8df8c..b1c8fd5 100644 --- a/spec/features/refinery/blog/admin/categories_spec.rb +++ b/spec/features/refinery/blog/admin/categories_spec.rb @@ -1,119 +1,121 @@ # encoding: utf-8 require 'spec_helper' -describe "Categories admin", type: :feature do - refinery_login_with :refinery_user +module Refinery + module Blog + module Admin + describe Category, type: :feature do + refinery_login_with_devise :authentication_devise_refinery_superuser - let(:title) { "lol" } + let(:title) { "lol" } - it "can create categories" do - visit refinery.admin_root_path + it "can create categories" do + visit refinery.admin_root_path - within("nav#menu") { click_link "Blog" } - within("nav.multilist") { click_link "Create new category" } + within("nav#menu") { click_link "Blog" } + within("nav.multilist") { click_link "Create new category" } - fill_in "Title", :with => title - click_button "Save" + fill_in "Title", :with => title + click_button "Save" - category = Refinery::Blog::Category.first - expect(category.title).to eq(title) - end - - context "with translations" do - before do - allow(Refinery::I18n).to receive(: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" - expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1) - @c = Refinery::Blog::Category.by_title("Testing Category") - end - - it "suceeds" do - expect(page).to have_content("'#{@c.title}' was successfully added.") - expect(Refinery::Blog::Category.count).to eq(1) - end - - it "shows locale for category" do - click_link "Manage" - within "#category_#{@c.id}" do - expect(page).to have_css(".locale_icon.en") - end - end - - it "shows up in blog page for default locale" do - visit refinery.blog_root_path - within "#categories" do - expect(page).to have_selector('li') - end - end - - it "does not show up in blog page for secondary locale" do - visit refinery.blog_root_path(:locale => :ru) - expect(page).not_to 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 - expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1) - @c = Refinery::Blog::Category.by_title(ru_category_title) - end - - it "suceeds" do - expect(page).to have_content("'#{@c.title}' was successfully added.") - expect(Refinery::Blog::Category.count).to eq(1) - end - - it "shows locale for category" do - click_link "Manage" - within "#category_#{@c.id}" do - expect(page).to have_css(".locale_icon.ru") - end - end - - it "does not show locale for primary locale" do - click_link "Manage" - within "#category_#{@c.id}" do - expect(page).not_to have_css(".locale_icon.en") + category = Refinery::Blog::Category.first + expect(category.title).to eq(title) end - end - - it "does not shows up in blog page for default locale" do - visit refinery.blog_root_path - expect(page).not_to have_selector('#categories') - end - it "shows up in blog page for secondary locale" do - visit refinery.blog_root_path(:locale => :ru) - within "#categories" do - expect(page).to have_selector('li') + context "with translations" do + before do + allow(Refinery::I18n).to receive(: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" + expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1) + @c = Refinery::Blog::Category.by_title("Testing Category") + end + + it "suceeds" do + expect(page).to have_content("'#{@c.title}' was successfully added.") + expect(Refinery::Blog::Category.count).to eq(1) + end + + it "shows locale for category" do + click_link "Manage" + within "#category_#{@c.id}" do + expect(page).to have_css(".locale_icon.en") + end + end + + it "shows up in blog page for default locale" do + visit refinery.blog_root_path + within "#categories" do + expect(page).to have_selector('li') + end + end + + it "does not show up in blog page for secondary locale" do + visit refinery.blog_root_path(:locale => :ru) + expect(page).not_to 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 + expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1) + @c = Refinery::Blog::Category.by_title(ru_category_title) + end + + it "suceeds" do + expect(page).to have_content("'#{@c.title}' was successfully added.") + expect(Refinery::Blog::Category.count).to eq(1) + end + + it "shows locale for category" do + click_link "Manage" + within "#category_#{@c.id}" do + expect(page).to have_css(".locale_icon.ru") + end + end + + it "does not show locale for primary locale" do + click_link "Manage" + within "#category_#{@c.id}" do + expect(page).not_to have_css(".locale_icon.en") + end + end + + it "does not shows up in blog page for default locale" do + visit refinery.blog_root_path + expect(page).not_to have_selector('#categories') + end + + it "shows up in blog page for secondary locale" do + visit refinery.blog_root_path(:locale => :ru) + within "#categories" do + expect(page).to have_selector('li') + end + end + end 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 index 097210d..1c6d67d 100644 --- a/spec/features/refinery/blog/admin/comments_spec.rb +++ b/spec/features/refinery/blog/admin/comments_spec.rb @@ -4,7 +4,7 @@ module Refinery module Blog module Admin describe Comment, type: :feature do - refinery_login_with :refinery_user + refinery_login_with_devise :authentication_devise_refinery_superuser describe "#index" do context "when has no new unapproved comments" do diff --git a/spec/features/refinery/blog/admin/menu_spec.rb b/spec/features/refinery/blog/admin/menu_spec.rb index 748d5c3..64f6461 100644 --- a/spec/features/refinery/blog/admin/menu_spec.rb +++ b/spec/features/refinery/blog/admin/menu_spec.rb @@ -1,13 +1,19 @@ require 'spec_helper' -describe "Blog menu entry", type: :feature do - refinery_login_with :refinery_user +module Refinery + module Blog + module Admin + describe Menu, type: :feature do + refinery_login_with_devise :authentication_devise_refinery_superuser - it "is highlighted when managing the blog" do - visit refinery.admin_root_path + it "is highlighted when managing the blog" do + visit refinery.admin_root_path - within("#menu") { click_link "Blog" } + within("#menu") { click_link "Blog" } - expect(page).to have_css("a.active", :text => "Blog") + expect(page).to have_css("a.active", :text => "Blog") + end + end + end end -end +end
\ No newline at end of file diff --git a/spec/features/refinery/blog/admin/posts_spec.rb b/spec/features/refinery/blog/admin/posts_spec.rb index 0efbb1d..ffb4b15 100644 --- a/spec/features/refinery/blog/admin/posts_spec.rb +++ b/spec/features/refinery/blog/admin/posts_spec.rb @@ -5,7 +5,7 @@ module Refinery module Blog module Admin describe Post, type: :feature do - refinery_login_with :refinery_user + refinery_login_with_devise :authentication_devise_refinery_superuser let!(:blog_category) do Globalize.with_locale(:en) { FactoryGirl.create(:blog_category) } @@ -58,7 +58,7 @@ module Refinery end it "should belong to me" do - expect(subject.class.first.author).to eq(::Refinery::User.last) + expect(subject.class.first.author).to eq(::Refinery::Blog.user_class.last) end it "should save categories" do @@ -153,7 +153,7 @@ module Refinery end context "with multiple users" do - let!(:other_guy) { FactoryGirl.create(:refinery_user, :username => "Other Guy") } + let!(:other_guy) { FactoryGirl.create(:authentication_devise_refinery_user, :username => "Other Guy") } describe "create blog post with alternate author" do before do @@ -210,13 +210,20 @@ module Refinery end it "shows up in blog page for default locale" do - visit refinery.blog_root_path + visit refinery.blog_admin_root_path expect(page).to 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) - expect(page).not_to have_selector("#post_#{@p.id}") + it "does show locale for default locale" do + within "#post_#{@p.id}" do + expect(page).to have_css(".locale_icon.en") + end + end + + it "does not show locale for secondary locale" do + within "#post_#{@p.id}" do + expect(page).not_to have_css(".locale_icon.ru") + end end end @@ -259,13 +266,14 @@ module Refinery end end - it "does not show up in blog page for default locale" do - visit refinery.blog_root_path - expect(page).not_to have_selector("#post_#{@p.id}") + it "does show locale for secondary locale" do + within "#post_#{@p.id}" do + expect(page).to have_css(".locale_icon.ru") + end end it "shows up in blog page for secondary locale" do - visit refinery.blog_root_path(:locale => :ru) + visit refinery.blog_admin_root_path(:locale => :ru) expect(page).to have_selector("#post_#{@p.id}") end diff --git a/spec/features/refinery/blog/categories_spec.rb b/spec/features/refinery/blog/categories_spec.rb index b778254..1ffe29f 100644 --- a/spec/features/refinery/blog/categories_spec.rb +++ b/spec/features/refinery/blog/categories_spec.rb @@ -1,28 +1,30 @@ require "spec_helper" module Refinery - describe "BlogCategories", type: :feature do - refinery_login_with :refinery_user + module Blog + describe Category, type: :feature do + refinery_login_with_devise :authentication_devise_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") + 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 - @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) - expect(page).to have_content("Refinery CMS blog post") - expect(page).to have_content("Video Games") + describe "show categories blog posts" do + it "should displays categories blog posts" do + visit refinery.blog_category_path(@category) + expect(page).to have_content("Refinery CMS blog post") + expect(page).to have_content("Video Games") + end end end end end -end +end
\ No newline at end of file diff --git a/spec/features/refinery/blog/posts_spec.rb b/spec/features/refinery/blog/posts_spec.rb index 3382398..816e11c 100644 --- a/spec/features/refinery/blog/posts_spec.rb +++ b/spec/features/refinery/blog/posts_spec.rb @@ -1,180 +1,182 @@ require "spec_helper" module Refinery - describe "Blog::Posts", type: :feature do - refinery_login_with :refinery_user + module Blog + describe Post, type: :feature do + refinery_login_with_devise :authentication_devise_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 + 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) + it "should display blog post" do + visit refinery.blog_post_path(blog_post) - expect(page).to have_content(blog_post.title) - end + expect(page).to have_content(blog_post.title) + end - describe "visit blog" do + describe "visit blog" do - before do - FactoryGirl.create(:page, :link_url => "/") - FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog") - end + 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 - expect(page).to have_content("Blog") - expect(page).to have_selector("a[href='/blog']") + it "shows blog link in menu" do + visit "/" + within "#menu" do + expect(page).to have_content("Blog") + expect(page).to have_selector("a[href='/blog']") + end + end + + it "shows blog posts" do + visit refinery.blog_root_path + expect(page).to have_content blog_post.title end - end - it "shows blog posts" do - visit refinery.blog_root_path - expect(page).to have_content blog_post.title end end - end - - describe "list tagged posts" do - context "when has tagged blog posts" do - let!(:tag_name) { "chicago" } - let!(:post) { - FactoryGirl.create(:blog_post, - :title => "I Love my city", - :tag_list => tag_name - ) - } - let!(:tag) { ::Refinery::Blog::Post.tag_counts_on(:tags).first } - - it "should have one tagged post" do - visit refinery.blog_tagged_posts_path(tag.id, tag_name.parameterize) - - expect(page).to have_content(tag_name) - expect(page).to have_content(post.title) + describe "list tagged posts" do + context "when has tagged blog posts" do + let!(:tag_name) { "chicago" } + let!(:post) { + FactoryGirl.create(:blog_post, + :title => "I Love my city", + :tag_list => tag_name + ) + } + let!(:tag) { ::Refinery::Blog::Post.tag_counts_on(:tags).first } + + it "should have one tagged post" do + visit refinery.blog_tagged_posts_path(tag.id, tag_name.parameterize) + + expect(page).to have_content(tag_name) + expect(page).to have_content(post.title) + end end end - end - describe "#show" do - context "when has no comments" do - let!(:blog_post) { FactoryGirl.create(:blog_post) } + 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) - expect(page).to have_content(blog_post.title) - expect(page).to have_content(blog_post.body) + it "should display the blog post" do + visit refinery.blog_post_path(blog_post) + expect(page).to have_content(blog_post.title) + expect(page).to have_content(blog_post.body) + end end - end - context "when has approved comments" do - let!(:approved_comment) { FactoryGirl.create(:approved_comment) } + 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) + it "should display the comments" do + visit refinery.blog_post_path(approved_comment.post) - expect(page).to have_content(approved_comment.body) - expect(page).to have_content("Posted by #{approved_comment.name}") + expect(page).to have_content(approved_comment.body) + expect(page).to have_content("Posted by #{approved_comment.name}") + end end - end - context "when has rejected comments" do - let!(:rejected_comment) { FactoryGirl.create(:rejected_comment) } + 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) + it "should not display the comments" do + visit refinery.blog_post_path(rejected_comment.post) - expect(page).not_to have_content(rejected_comment.body) + expect(page).not_to have_content(rejected_comment.body) + end end - end - context "when has new comments" do - let!(:blog_comment) { FactoryGirl.create(:blog_comment) } + 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) + it "should not display the comments" do + visit refinery.blog_post_path(blog_comment.post) - expect(page).not_to have_content(blog_comment.body) + expect(page).not_to have_content(blog_comment.body) + end 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." } + 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) + 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 + 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 + it "creates the comment" do + comment = blog_post.reload.comments.last - expect(comment.name).to eq(name) - expect(comment.email).to eq(email) - expect(comment.body).to eq(body) + expect(comment.name).to eq(name) + expect(comment.email).to eq(email) + expect(comment.body).to eq(body) + end end - end - context "post popular" do - let!(:blog_post) { FactoryGirl.create(:blog_post) } - let!(:blog_post2) { FactoryGirl.create(:blog_post) } + 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 + before do + visit refinery.blog_post_path(blog_post) + end - it "should increment access count" do - expect(blog_post.reload.access_count).to eq(1) - visit refinery.blog_post_path(blog_post) - expect(blog_post.reload.access_count).to eq(2) - end + it "should increment access count" do + expect(blog_post.reload.access_count).to eq(1) + visit refinery.blog_post_path(blog_post) + expect(blog_post.reload.access_count).to eq(2) + end - it "should be most popular" do - expect(Refinery::Blog::Post.popular(2).first).to eq(blog_post) + it "should be most popular" do + expect(Refinery::Blog::Post.popular(2).first).to eq(blog_post) + end 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) } + 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 - expect(Refinery::Blog::Post.recent(2).first.id).to eq(blog_post2.id) + it "should be the most recent" do + expect(Refinery::Blog::Post.recent(2).first.id).to eq(blog_post2.id) + end end - end - end + end - describe "#show draft preview" do - let!(:blog_post) { FactoryGirl.create(:blog_post_draft) } + 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) + context "when logged in as admin" do + it "should display the draft notification" do + visit refinery.blog_post_path(blog_post) - expect(page).to have_content('This page is NOT live for public viewing.') + expect(page).to have_content('This page is NOT live for public viewing.') + end 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 + 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) + it "should not display the blog post" do + visit refinery.blog_post_path(blog_post) - expect(page).to have_content("The page you requested was not found.") + expect(page).to have_content("The page you requested was not found.") + end end end end diff --git a/spec/models/refinery/blog/category_spec.rb b/spec/models/refinery/blog/category_spec.rb index 577cb9d..4e40269 100644 --- a/spec/models/refinery/blog/category_spec.rb +++ b/spec/models/refinery/blog/category_spec.rb @@ -4,7 +4,7 @@ module Refinery module Blog describe Category, type: :model do let(:category) { FactoryGirl.create(:blog_category) } - let(:refinery_user) { FactoryGirl.create(:refinery_user) } + let(:author) { FactoryGirl.create(:authentication_devise_refinery_user) } describe "validations" do it "requires title" do @@ -25,12 +25,12 @@ module Refinery first_post = category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday, - :author => refinery_user }) + :author => author }) latest_post = category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now, - :author => refinery_user }) + :author => author }) expect(category.posts.newest_first.first).to eq(latest_post) end |