aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb2
-rw-r--r--app/models/refinery/blog/category.rb4
-rw-r--r--app/models/refinery/blog/post.rb6
-rw-r--r--spec/features/refinery/blog/admin/categories_spec.rb8
-rw-r--r--spec/features/refinery/blog/admin/posts_spec.rb4
-rw-r--r--spec/spec_helper.rb2
6 files changed, 17 insertions, 9 deletions
diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb
index 1cc9698..2e504f7 100644
--- a/app/controllers/refinery/blog/posts_controller.rb
+++ b/app/controllers/refinery/blog/posts_controller.rb
@@ -41,7 +41,7 @@ module Refinery
if @comment.valid?
if Comment::Moderation.enabled? or @comment.ham?
begin
- CommentMailer.notification(@comment, request).deliver
+ CommentMailer.notification(@comment, request).deliver_now
rescue
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
end
diff --git a/app/models/refinery/blog/category.rb b/app/models/refinery/blog/category.rb
index 5cf4ea5..ca3824e 100644
--- a/app/models/refinery/blog/category.rb
+++ b/app/models/refinery/blog/category.rb
@@ -12,6 +12,10 @@ module Refinery
validates :title, :presence => true, :uniqueness => true
+ def self.by_title(title)
+ joins(:translations).find_by(title: title)
+ end
+
def self.translated
with_translations(::Globalize.locale)
end
diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb
index f80a939..c64c8f2 100644
--- a/app/models/refinery/blog/post.rb
+++ b/app/models/refinery/blog/post.rb
@@ -78,7 +78,7 @@ module Refinery
def find_by_slug_or_id(slug_or_id)
if slug_or_id.friendly_id?
- find_by_slug(slug_or_id)
+ friendly.find(slug_or_id)
else
find(slug_or_id)
end
@@ -92,6 +92,10 @@ module Refinery
newest_first.where(:published_at => date.beginning_of_year..date.end_of_year).with_globalize
end
+ def by_title(title)
+ joins(:translations).find_by(:title => title)
+ end
+
def newest_first
order("published_at DESC")
end
diff --git a/spec/features/refinery/blog/admin/categories_spec.rb b/spec/features/refinery/blog/admin/categories_spec.rb
index b3e3f31..7a8df8c 100644
--- a/spec/features/refinery/blog/admin/categories_spec.rb
+++ b/spec/features/refinery/blog/admin/categories_spec.rb
@@ -35,8 +35,8 @@ describe "Categories admin", type: :feature do
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")
+ expect { click_button "Save" }.to change(Refinery::Blog::Category, :count).by(1)
+ @c = Refinery::Blog::Category.by_title("Testing Category")
end
it "suceeds" do
@@ -76,8 +76,8 @@ describe "Categories admin", type: :feature 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)
+ 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
diff --git a/spec/features/refinery/blog/admin/posts_spec.rb b/spec/features/refinery/blog/admin/posts_spec.rb
index 230b64c..9faf061 100644
--- a/spec/features/refinery/blog/admin/posts_spec.rb
+++ b/spec/features/refinery/blog/admin/posts_spec.rb
@@ -200,7 +200,7 @@ module Refinery
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")
+ @p = Refinery::Blog::Post.by_title("Post")
end
it "succeeds" do
@@ -239,7 +239,7 @@ module Refinery
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(ru_page_title)
+ @p = Refinery::Blog::Post.by_title(ru_page_title)
end
it "succeeds" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 7b20bf0..bddb8bc 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,5 +1,4 @@
require 'rubygems'
-require 'capybara/poltergeist'
# Configure Rails Environment
ENV["RAILS_ENV"] ||= 'test'
@@ -18,6 +17,7 @@ RSpec.configure do |config|
end
# set javascript driver for capybara
+require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
# Requires supporting files with custom matchers and macros, etc,