-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
174 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ Gemfile.lock | |
.ruby-version | ||
/.sass-cache | ||
coverage/ | ||
# Ignore Rubymine files | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
class Comfy::Blog::Comment < ActiveRecord::Base | ||
|
||
self.table_name = 'comfy_blog_comments' | ||
|
||
# -- Relationships -------------------------------------------------------- | ||
belongs_to :post | ||
|
||
# -- Callbacks ------------------------------------------------------------ | ||
before_create :set_is_published | ||
|
||
# -- Validations ---------------------------------------------------------- | ||
validates :post_id, :content, :author, :email, | ||
validates :post_id, :content, :author, :email, | ||
:presence => true | ||
validates :email, | ||
:format => { :with => /\A([\w.%-+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i } | ||
|
||
|
||
validate :check_commentable | ||
|
||
# -- Scopes --------------------------------------------------------------- | ||
scope :published, -> { | ||
where(:is_published => true) | ||
} | ||
|
||
protected | ||
|
||
def set_is_published | ||
self.is_published = ComfyBlog.config.auto_publish_comments | ||
return | ||
end | ||
|
||
|
||
def check_commentable | ||
errors.add(:base, 'comments are not allowed') if post.try(:comments_disabled?) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- @post.comments.published.each do |comment| | ||
.comment | ||
.author= comment.author | ||
.content= comment.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,82 @@ | ||
require_relative '../../../test_helper' | ||
|
||
class Comfy::Blog::PostsControllerTest < ActionController::TestCase | ||
|
||
def setup | ||
@blog = comfy_blog_blogs(:default) | ||
@post = comfy_blog_posts(:default) | ||
@second_post = comfy_blog_posts(:not_commentable) | ||
end | ||
|
||
def test_get_index | ||
get :serve | ||
assert_response :success | ||
assert_template :index | ||
assert assigns(:posts) | ||
assert_equal 1, assigns(:posts).size | ||
assert_equal 2, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_as_rss | ||
get :serve, :format => :rss | ||
assert_response :success | ||
assert_template :index | ||
assert assigns(:posts) | ||
assert_equal 1, assigns(:posts).size | ||
assert_equal 2, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_with_unpublished | ||
comfy_blog_posts(:default).update_column(:is_published, false) | ||
get :serve | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
assert_equal 1, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_for_year_archive | ||
get :index, :year => 2012 | ||
assert_response :success | ||
assert_equal 1, assigns(:posts).size | ||
assert_equal 2, assigns(:posts).size | ||
|
||
get :index, :year => 1999 | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_for_month_archive | ||
get :index, :year => 2012, :month => 1 | ||
assert_response :success | ||
assert_equal 1, assigns(:posts).size | ||
assert_equal 2, assigns(:posts).size | ||
|
||
get :index, :year => 2012, :month => 12 | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
end | ||
|
||
def test_get_show | ||
get :serve, :slug => @post.slug | ||
assert_response :success | ||
assert_template :show | ||
assert assigns(:post) | ||
end | ||
|
||
def test_get_show_unpublished | ||
@post.update_attribute(:is_published, false) | ||
@second_post.update_attribute(:is_published, false) | ||
assert_exception_raised ComfortableMexicanSofa::MissingPage do | ||
get :serve, :slug => @post.slug | ||
end | ||
end | ||
|
||
def test_get_show_with_date | ||
get :show, :year => @post.year, :month => @post.month, :slug => @post.slug | ||
assert_response :success | ||
assert_template :show | ||
assert assigns(:post) | ||
end | ||
|
||
def test_get_show_with_date_invalid | ||
assert_exception_raised ComfortableMexicanSofa::MissingPage do | ||
get :show, :year => '1999', :month => '99', :slug => 'invalid' | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.