diff options
22 files changed, 468 insertions, 72 deletions
@@ -5,11 +5,13 @@ gemspec gem 'refinerycms', :git => 'git://github.com/resolve/refinerycms.git' gem 'refinerycms-i18n', :git => 'git://github.com/parndt/refinerycms-i18n.git' gem 'refinerycms-settings', :git => 'git://github.com/parndt/refinerycms-settings.git' +gem 'refinerycms-i18n', :git => 'git://github.com/parndt/refinerycms-i18n.git' group :development, :test do require 'rbconfig' gem 'refinerycms-testing', :git => 'git://github.com/resolve/refinerycms.git' + gem 'guard-rspec', '~> 0.6.0' platforms :jruby do gem 'activerecord-jdbcsqlite3-adapter' @@ -1,4 +1,4 @@ -guard 'rspec', :version => 2, :cli => "--format Fuubar --color --drb" do +guard 'rspec', :version => 2, :cli => "--color --drb" do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } diff --git a/app/controllers/refinery/blog/admin/posts_controller.rb b/app/controllers/refinery/blog/admin/posts_controller.rb index b379a24..e48c00d 100644 --- a/app/controllers/refinery/blog/admin/posts_controller.rb +++ b/app/controllers/refinery/blog/admin/posts_controller.rb @@ -6,7 +6,8 @@ module Refinery cache_sweeper Refinery::BlogSweeper crudify :'refinery/blog/post', - :order => 'published_at DESC' + :order => 'published_at DESC', + :include => [:translations] before_filter :find_all_categories, :only => [:new, :edit, :create, :update] @@ -77,6 +78,10 @@ module Refinery end protected + def find_post + @post = Refinery::Blog::Post.find_by_slug_or_id(params[:id]) + end + def find_all_categories @categories = Refinery::Blog::Category.find(:all) end diff --git a/app/controllers/refinery/blog/categories_controller.rb b/app/controllers/refinery/blog/categories_controller.rb index 467726e..23a835a 100644 --- a/app/controllers/refinery/blog/categories_controller.rb +++ b/app/controllers/refinery/blog/categories_controller.rb @@ -4,7 +4,7 @@ module Refinery def show @category = Refinery::Blog::Category.find(params[:id]) - @posts = @category.posts.live.includes(:comments, :categories).page(params[:page]) + @posts = @category.posts.live.includes(:comments, :categories).with_globalize.page(params[:page]) end end diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb index caa46ec..bb242fd 100644 --- a/app/controllers/refinery/blog/posts_controller.rb +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -12,7 +12,7 @@ module Refinery def index # Rss feeders are greedy. Let's give them every blog post instead of paginating. - (@posts = Post.live.includes(:comments, :categories).all) if request.format.rss? + (@posts = Post.live.includes(:comments, :categories).with_globalize) if request.format.rss? respond_with (@posts) do |format| format.html format.rss @@ -22,7 +22,7 @@ module Refinery def show @comment = Comment.new - @canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical? + @canonical = refinery.url_for(:locale => Refinery::I18n.current_frontend_locale) if canonical? @post.increment!(:access_count, 1) diff --git a/app/helpers/refinery/blog/controller_helper.rb b/app/helpers/refinery/blog/controller_helper.rb index bf4926b..87d5447 100644 --- a/app/helpers/refinery/blog/controller_helper.rb +++ b/app/helpers/refinery/blog/controller_helper.rb @@ -1,11 +1,11 @@ module Refinery module Blog module ControllerHelper - + protected - + def find_blog_post - unless (@post = Refinery::Blog::Post.find(params[:id])).try(:live?) + unless (@post = Refinery::Blog::Post.with_globalize.find(params[:id])).try(:live?) if refinery_user? and current_refinery_user.authorized_plugins.include?("refinerycms_blog") @post = Refinery::Blog::Post.find(params[:id]) else @@ -13,16 +13,16 @@ module Refinery end end end - + def find_all_blog_posts - @posts = Refinery::Blog::Post.live.includes(:comments, :categories).page(params[:page]) + @posts = Refinery::Blog::Post.live.includes(:comments, :categories).with_globalize.page(params[:page]) end def find_tags @tags = Refinery::Blog::Post.tag_counts_on(:tags) end def find_all_blog_categories - @categories = Refinery::Blog::Category.all + @categories = Refinery::Blog::Category.translated end end end diff --git a/app/models/refinery/blog/category.rb b/app/models/refinery/blog/category.rb index 2935c89..36e6816 100644 --- a/app/models/refinery/blog/category.rb +++ b/app/models/refinery/blog/category.rb @@ -1,8 +1,11 @@ module Refinery module Blog class Category < ActiveRecord::Base + + translates :title, :slug + extend FriendlyId - friendly_id :title, :use => [:slugged] + friendly_id :title, :use => [:slugged, :globalize] has_many :categorizations, :dependent => :destroy, :foreign_key => :blog_category_id has_many :posts, :through => :categorizations, :source => :blog_post @@ -12,9 +15,18 @@ module Refinery validates :title, :presence => true, :uniqueness => true attr_accessible :title + attr_accessor :locale + + class Translation + attr_accessible :locale + end + + def self.translated + with_translations(::Globalize.locale) + end def post_count - posts.live.count + posts.live.with_globalize.count end # how many items to show per page diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb index c32b775..024872e 100644 --- a/app/models/refinery/blog/post.rb +++ b/app/models/refinery/blog/post.rb @@ -4,8 +4,11 @@ require 'seo_meta' module Refinery module Blog class Post < ActiveRecord::Base + + translates :title, :body, :custom_url, :custom_teaser, :slug, :include => :seo_meta + extend FriendlyId - friendly_id :friendly_id_source, :use => [:slugged] + friendly_id :friendly_id_source, :use => [:slugged, :globalize] is_seo_meta if self.table_exists? @@ -33,6 +36,13 @@ module Refinery attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url, :author attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids attr_accessible :source_url, :source_url_title + attr_accessor :locale + + + class Translation + is_seo_meta + attr_accessible :browser_title, :meta_description, :meta_keywords, :locale + end self.per_page = Refinery::Blog.posts_per_page @@ -53,45 +63,67 @@ module Refinery end class << self + + # Wrap up the logic of finding the pages based on the translations table. + def with_globalize(conditions = {}) + conditions = {:locale => ::Globalize.locale}.merge(conditions) + globalized_conditions = {} + conditions.keys.each do |key| + if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s) + globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key) + end + end + # A join implies readonly which we don't really want. + joins(:translations).where(globalized_conditions).where(conditions).readonly(false) + end + + def find_by_slug_or_id(slug_or_id) + if slug_or_id.friendly_id? + find_by_slug(slug_or_id) + else + find(slug_or_id) + end + end + def by_month(date) - where(:published_at => date.beginning_of_month..date.end_of_month) + where(:published_at => date.beginning_of_month..date.end_of_month).with_globalize end - + def by_archive(date) Refinery.deprecate("Refinery::Blog::Post.by_archive(date)", {:replacement => "Refinery::Blog::Post.by_month(date)", :when => 2.2 }) by_month(date) end - + def by_year(date) - where(:published_at => date.beginning_of_year..date.end_of_year) + where(:published_at => date.beginning_of_year..date.end_of_year).with_globalize end def published_dates_older_than(date) - published_before(date).pluck(:published_at) + published_before(date).with_globalize.pluck(:published_at) end def recent(count) - live.limit(count) + live.limit(count).with_globalize end def popular(count) - unscoped.order("access_count DESC").limit(count) + unscoped.order("access_count DESC").limit(count).with_globalize end def previous(item) - published_before(item.published_at).first + published_before(item.published_at).with_globalize.first end def uncategorized - live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) + live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }).with_globalize end def next(current_record) - where(["published_at > ? and draft = ?", current_record.published_at, false]).first + where(["published_at > ? and draft = ?", current_record.published_at, false]).with_globalize.first end def published_before(date=Time.now) - where("published_at < ? and draft = ?", date, false) + where("published_at < ? and draft = ?", date, false).with_globalize end alias_method :live, :published_before diff --git a/app/models/refinery/categorization.rb b/app/models/refinery/categorization.rb index ec51ea7..688da6a 100644 --- a/app/models/refinery/categorization.rb +++ b/app/models/refinery/categorization.rb @@ -4,7 +4,7 @@ module Refinery self.table_name = 'refinery_blog_categories_blog_posts' belongs_to :blog_post, :class_name => 'Refinery::Blog::Post', :foreign_key => :blog_post_id belongs_to :blog_category, :class_name => 'Refinery::Blog::Category', :foreign_key => :blog_category_id - + attr_accessible :blog_category_id, :blog_post_id end -end
\ No newline at end of file +end diff --git a/app/views/refinery/blog/admin/categories/_category.html.erb b/app/views/refinery/blog/admin/categories/_category.html.erb index b7d352f..d31e4e6 100644 --- a/app/views/refinery/blog/admin/categories/_category.html.erb +++ b/app/views/refinery/blog/admin/categories/_category.html.erb @@ -1,7 +1,15 @@ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(category) -%>"> <span class='title'> - <%= category.title %> - <span class="preview"> </span> + <%= category.title.presence || category.translations.detect {|t| t.title.present?}.title %> + <span class="preview"> + <% category.translations.each do |translation| %> + <% if translation.title.present? %> + <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'), + refinery.edit_blog_admin_category_path(category, :switch_locale => translation.locale), + :class => 'locale' %> + <% end %> + <% end %> + </span> </span> <span class='actions'> <%= link_to refinery_icon_tag("application_edit.png"), diff --git a/app/views/refinery/blog/admin/categories/_form.html.erb b/app/views/refinery/blog/admin/categories/_form.html.erb index b1cf16c..6b4e20d 100644 --- a/app/views/refinery/blog/admin/categories/_form.html.erb +++ b/app/views/refinery/blog/admin/categories/_form.html.erb @@ -5,6 +5,9 @@ :include_object_name => true } %> + <%= render "/refinery/blog/admin/shared/locale_picker", + :current_locale => Thread.current[:globalize_locale] if Refinery.i18n_enabled? %> + <div class='field'> <%= f.label :title -%> <%= f.text_field :title, :class => 'larger widest' -%> diff --git a/app/views/refinery/blog/admin/posts/_form.html.erb b/app/views/refinery/blog/admin/posts/_form.html.erb index a977754..b6fc535 100644 --- a/app/views/refinery/blog/admin/posts/_form.html.erb +++ b/app/views/refinery/blog/admin/posts/_form.html.erb @@ -5,6 +5,9 @@ :include_object_name => true } %> + <%= render "/refinery/blog/admin/shared/locale_picker", + :current_locale => Thread.current[:globalize_locale] if Refinery.i18n_enabled? %> + <div class='field'> <%= f.label :title -%> <%= f.text_field :title, :class => 'larger widest' -%> diff --git a/app/views/refinery/blog/admin/posts/_post.html.erb b/app/views/refinery/blog/admin/posts/_post.html.erb index fea3eb8..781595a 100644 --- a/app/views/refinery/blog/admin/posts/_post.html.erb +++ b/app/views/refinery/blog/admin/posts/_post.html.erb @@ -1,7 +1,16 @@ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(post) -%>"> <span class='title'> - <%= post.title %> + <%= post.title.presence || post.translations.detect {|t| t.title.present?}.title %> <span class="preview"> + <% post.translations.each do |translation| %> + <% if translation.title.present? %> + <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'), + refinery.edit_blog_admin_post_path(post, :switch_locale => translation.locale), + :class => 'locale' %> + <% end %> + <% end %> + + <%= post.published_at.try(:strftime, '%b %d, %Y') || 'draft' %> <%= " by #{post.author.username}" if post.author.present? %> <% if post.draft? %> <span class="label notice"><%= t('refinery.blog.admin.posts.post.draft') %></span> diff --git a/app/views/refinery/blog/admin/shared/_locale_picker.html.erb b/app/views/refinery/blog/admin/shared/_locale_picker.html.erb new file mode 100644 index 0000000..e162364 --- /dev/null +++ b/app/views/refinery/blog/admin/shared/_locale_picker.html.erb @@ -0,0 +1,11 @@ +<input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' /> +<% if (locales ||= Refinery::I18n.frontend_locales).present? and locales.many? %> + <ul id='switch_locale_picker' class='clearfix'> + <% locales.each do |locale| %> + <li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>> + <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"), + refinery.url_for(:switch_locale => locale) %> + </li> + <% end %> + </ul> +<% end %> diff --git a/app/views/refinery/blog/shared/_post.html.erb b/app/views/refinery/blog/shared/_post.html.erb index 5b90c8e..40ae70b 100644 --- a/app/views/refinery/blog/shared/_post.html.erb +++ b/app/views/refinery/blog/shared/_post.html.erb @@ -7,7 +7,7 @@ <%= t('created_at', :scope => 'refinery.blog.shared.posts', :when => l(post.published_at.to_date, :format => :short)) %> </time> <%= "#{t('by', :scope => 'refinery.blog.posts.show')} #{post.author.username}" if post.author.present? %>. - <% if (categories = post.categories).any? %> + <% if (categories = post.categories.translated).any? %> <aside class='filed_in'> <%= t('filed_in', :scope => 'refinery.blog.posts.show') %> <%=raw categories.collect { |category| link_to category.title, refinery.blog_category_path(category) }.to_sentence %> diff --git a/db/migrate/20120530102901_create_blog_translations.rb b/db/migrate/20120530102901_create_blog_translations.rb new file mode 100644 index 0000000..c301f42 --- /dev/null +++ b/db/migrate/20120530102901_create_blog_translations.rb @@ -0,0 +1,17 @@ +class CreateBlogTranslations < ActiveRecord::Migration + def up + Refinery::Blog::Post.create_translation_table!({ + :body => :text, + :custom_teaser => :text, + :custom_url => :string, + :slug => :string, + :title => :string + }, { + :migrate_data => true + }) + end + + def down + Refinery::Blog::Post.drop_translation_table! :migrate_data => true + end +end diff --git a/db/migrate/20120531113632_delete_cached_slugs.rb b/db/migrate/20120531113632_delete_cached_slugs.rb new file mode 100644 index 0000000..14c8653 --- /dev/null +++ b/db/migrate/20120531113632_delete_cached_slugs.rb @@ -0,0 +1,6 @@ +class DeleteCachedSlugs < ActiveRecord::Migration + def change + remove_column Refinery::Blog::Category.table_name, :cached_slug + remove_column Refinery::Blog::Post.table_name, :cached_slug + end +end diff --git a/db/migrate/20120601151114_create_category_translations.rb b/db/migrate/20120601151114_create_category_translations.rb new file mode 100644 index 0000000..a7cb956 --- /dev/null +++ b/db/migrate/20120601151114_create_category_translations.rb @@ -0,0 +1,14 @@ +class CreateCategoryTranslations < ActiveRecord::Migration + def up + Refinery::Blog::Category.create_translation_table!({ + :title => :string, + :slug => :string + }, { + :migrate_data => true + }) + end + + def down + Refinery::Blog::Category.drop_translation_table! :migrate_data => true + end +end 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 |