blogit 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +39 -0
- data/app/assets/javascripts/blogit/index.js +1 -0
- data/app/assets/stylesheets/blogit/comments.css +16 -0
- data/app/assets/stylesheets/blogit/index.css +3 -0
- data/app/assets/stylesheets/blogit/posts.css +59 -0
- data/app/controllers/blogit/application_controller.rb +41 -0
- data/app/controllers/blogit/comments_controller.rb +44 -0
- data/app/controllers/blogit/posts_controller.rb +55 -0
- data/app/helpers/blogit/application_helper.rb +64 -0
- data/app/helpers/blogit/comments_helper.rb +19 -0
- data/app/helpers/blogit/posts_helper.rb +26 -0
- data/app/models/blogit/comment.rb +59 -0
- data/app/models/blogit/post.rb +57 -0
- data/app/views/blogit/comments/_comment.html.erb +16 -0
- data/app/views/blogit/comments/_form.html.erb +42 -0
- data/app/views/blogit/comments/create.js.erb +7 -0
- data/app/views/blogit/comments/destroy.js.erb +1 -0
- data/app/views/blogit/posts/_blog_post_spacer.html.erb +1 -0
- data/app/views/blogit/posts/_blogger_information.html.erb +4 -0
- data/app/views/blogit/posts/_comments_count.html.erb +5 -0
- data/app/views/blogit/posts/_form.html.erb +43 -0
- data/app/views/blogit/posts/_pagination.html.erb +1 -0
- data/app/views/blogit/posts/_post.html.erb +19 -0
- data/app/views/blogit/posts/_post_body.html.erb +1 -0
- data/app/views/blogit/posts/_post_head.html.erb +3 -0
- data/app/views/blogit/posts/_post_links.html.erb +5 -0
- data/app/views/blogit/posts/edit.html.erb +3 -0
- data/app/views/blogit/posts/index.html.erb +10 -0
- data/app/views/blogit/posts/new.html.erb +3 -0
- data/app/views/blogit/posts/show.html.erb +7 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20110814091434_create_blog_posts.rb +12 -0
- data/db/migrate/20110814093229_create_blog_comments.rb +15 -0
- data/db/migrate/20110814103306_acts_as_taggable_on_migration.rb +28 -0
- data/lib/blogit.rb +24 -0
- data/lib/blogit/blogs.rb +19 -0
- data/lib/blogit/configuration.rb +74 -0
- data/lib/blogit/engine.rb +14 -0
- data/lib/blogit/parsers.rb +5 -0
- data/lib/blogit/parsers/html_parser.rb +9 -0
- data/lib/blogit/parsers/markdown_parser.rb +21 -0
- data/lib/blogit/parsers/textile_parser.rb +13 -0
- data/lib/blogit/version.rb +3 -0
- data/lib/generators/blogit/USAGE +8 -0
- data/lib/generators/blogit/install_generator.rb +15 -0
- data/lib/generators/templates/blogit.rb +42 -0
- data/lib/tasks/blog_tasks.rake +4 -0
- data/lib/validators.rb +3 -0
- data/lib/validators/absence_validator.rb +13 -0
- data/spec/blogit_spec.rb +20 -0
- data/spec/controllers/blogit/comments_controller_spec.rb +111 -0
- data/spec/controllers/blogit/posts_controller_spec.rb +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +18 -0
- data/spec/dummy/app/controllers/application_controller.rb +19 -0
- data/spec/dummy/app/controllers/people_controller.rb +83 -0
- data/spec/dummy/app/controllers/sessions_controller.rb +23 -0
- data/spec/dummy/app/controllers/users_controller.rb +83 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/people_helper.rb +2 -0
- data/spec/dummy/app/helpers/sessions_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/models/person.rb +2 -0
- data/spec/dummy/app/models/user.rb +11 -0
- data/spec/dummy/app/views/layouts/application.html.erb +28 -0
- data/spec/dummy/app/views/people/_form.html.erb +21 -0
- data/spec/dummy/app/views/people/edit.html.erb +6 -0
- data/spec/dummy/app/views/people/index.html.erb +23 -0
- data/spec/dummy/app/views/people/new.html.erb +5 -0
- data/spec/dummy/app/views/people/show.html.erb +10 -0
- data/spec/dummy/app/views/sessions/new.html.erb +17 -0
- data/spec/dummy/app/views/users/_form.html.erb +25 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +25 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +15 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +25 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/blogit.rb +40 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +11 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20110814091304_create_users.rb +10 -0
- data/spec/dummy/db/migrate/20110819103335_create_people.rb +9 -0
- data/spec/dummy/db/schema.rb +71 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +21145 -0
- data/spec/dummy/log/test.log +32053 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/people.yml +7 -0
- data/spec/dummy/test/fixtures/users.yml +9 -0
- data/spec/dummy/test/functional/people_controller_test.rb +49 -0
- data/spec/dummy/test/functional/sessions_controller_test.rb +9 -0
- data/spec/dummy/test/functional/users_controller_test.rb +49 -0
- data/spec/dummy/test/unit/helpers/people_helper_test.rb +4 -0
- data/spec/dummy/test/unit/helpers/sessions_helper_test.rb +4 -0
- data/spec/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/spec/dummy/test/unit/person_test.rb +7 -0
- data/spec/dummy/test/unit/user_test.rb +7 -0
- data/spec/dummy/tmp/cache/assets/BC4/870/sprockets%2F64a399278031122c8576726e146081d5 +0 -0
- data/spec/dummy/tmp/cache/assets/C49/710/sprockets%2F8a389a2323475a7053fc419c4103814f +0 -0
- data/spec/dummy/tmp/cache/assets/C9E/F00/sprockets%2Fdbb1755717649d42fe9df99326657618 +0 -0
- data/spec/dummy/tmp/cache/assets/CAA/0C0/sprockets%2Feec4505e23136c45e543a609b0c69554 +0 -0
- data/spec/dummy/tmp/cache/assets/CDE/240/sprockets%2Fcf7da81f64139020d3a4a78f904609c4 +0 -0
- data/spec/dummy/tmp/cache/assets/CEF/560/sprockets%2Fa1bf08ab120c72351b460a65e4800af6 +0 -0
- data/spec/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/D08/D50/sprockets%2F36daa544802ddf93249b8d07dab81125 +0 -0
- data/spec/dummy/tmp/cache/assets/D0A/410/sprockets%2F7e74a40717d2324f9a30ddff29ea5124 +0 -0
- data/spec/dummy/tmp/cache/assets/D0E/C00/sprockets%2F3091a34f307d562f44ee24f4c776baa9 +0 -0
- data/spec/dummy/tmp/cache/assets/D0F/180/sprockets%2F1ea0059d1fca1d25898ff37c7c150944 +0 -0
- data/spec/dummy/tmp/cache/assets/D10/610/sprockets%2F5883b6e94dcea7e32d57de13201563c3 +0 -0
- data/spec/dummy/tmp/cache/assets/D11/D20/sprockets%2Fcac21eac42152981882bf9e489316af4 +0 -0
- data/spec/dummy/tmp/cache/assets/D1F/730/sprockets%2F2f81ed50f6f293b326c576a8528ce9f3 +0 -0
- data/spec/dummy/tmp/cache/assets/D22/380/sprockets%2Fda1670e413fe4633d84eb9394fd7797c +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D33/240/sprockets%2Ffd4446a4ab97006a073ba30d57fdd617 +0 -0
- data/spec/dummy/tmp/cache/assets/D34/140/sprockets%2F0d8b2740eca50a83fc91e51292f9f00c +0 -0
- data/spec/dummy/tmp/cache/assets/D34/680/sprockets%2Fb2cb3891a4cb197ecb1a37299d14c531 +0 -0
- data/spec/dummy/tmp/cache/assets/D3C/3A0/sprockets%2F40c65286b76c2cbc9d2bd92a60e7f126 +0 -0
- data/spec/dummy/tmp/cache/assets/D3D/C40/sprockets%2F4654852579bc0bea406bcd54d38a7dc3 +0 -0
- data/spec/dummy/tmp/cache/assets/D46/650/sprockets%2Ff56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
- data/spec/dummy/tmp/cache/assets/D58/1E0/sprockets%2Fdd863e40bd669f77bb549b257d88d6b5 +0 -0
- data/spec/dummy/tmp/cache/assets/D61/6F0/sprockets%2F02da53eeca228bcef0c49278517111fe +0 -0
- data/spec/dummy/tmp/cache/assets/D63/720/sprockets%2Fe625e6b0d13c0bd8ca548a48e1d4508b +0 -0
- data/spec/dummy/tmp/cache/assets/D70/D70/sprockets%2Fc9ac544160bbcc29d775b54ca8f0269f +0 -0
- data/spec/dummy/tmp/cache/assets/D73/220/sprockets%2F3dbc0a37f98fb43ec819b85a64d32c55 +0 -0
- data/spec/dummy/tmp/cache/assets/D7A/BD0/sprockets%2Ff645c87585af5bf4be27a271f20b39ff +0 -0
- data/spec/dummy/tmp/cache/assets/D80/960/sprockets%2F269feebf3271f38b09bd01e9b748f77d +0 -0
- data/spec/dummy/tmp/cache/assets/D82/800/sprockets%2F72f633d76779cbfb7d9a57b5623c3faf +0 -0
- data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
- data/spec/dummy/tmp/cache/assets/D8D/EA0/sprockets%2Fe64949cb167a0aa27a33a1adf1d544be +0 -0
- data/spec/dummy/tmp/cache/assets/DCA/9B0/sprockets%2Fdf0e8f8a85e5d4056b3fe1cec3b7131a +0 -0
- data/spec/dummy/tmp/cache/assets/DF3/BA0/sprockets%2Ffddeae525be5a563ca0d194b614bf64b +0 -0
- data/spec/dummy/tmp/cache/assets/DFF/B40/sprockets%2Fe0d60af9df95b2a58c278acd3f2beb55 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E0A/870/sprockets%2Fbba31cc2875be0fddf5901fef9b99e48 +0 -0
- data/spec/dummy/tmp/cache/assets/E27/590/sprockets%2F097d2347f3f9d2ec19abefaaa5dd0ec1 +0 -0
- data/spec/dummy/tmp/cache/assets/E30/DC0/sprockets%2F9ddd7093ee1d47cbacd526f4bdd36e3c +0 -0
- data/spec/dummy/tmp/cache/assets/E49/530/sprockets%2F10dadda372ee79deb251d7bbbb025cec +0 -0
- data/spec/dummy/tmp/cache/assets/E82/4C0/sprockets%2F0d49c3fa07b559dbecbaabf2a4bad9c8 +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/factories.rb +28 -0
- data/spec/helpers/blogit/application_helper_spec.rb +14 -0
- data/spec/helpers/blogit/posts_helper_spec.rb +34 -0
- data/spec/lib/blogs_spec.rb +23 -0
- data/spec/lib/configuration_spec.rb +57 -0
- data/spec/lib/parsers/html_parser_spec.rb +12 -0
- data/spec/lib/parsers/markdown_parser_spec.rb +12 -0
- data/spec/lib/parsers/textile_parser_spec.rb +12 -0
- data/spec/models/blogit/comment_spec.rb +64 -0
- data/spec/models/blogit/post_spec.rb +153 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/authentication.rb +9 -0
- data/spec/support/configuration.rb +5 -0
- metadata +415 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
isolate_namespace Blogit
|
|
4
|
+
|
|
5
|
+
config.to_prepare do
|
|
6
|
+
|
|
7
|
+
if defined?(::ActiveRecord::Base)
|
|
8
|
+
::ActiveRecord::Base.send(:include, Blogit::Blogs)
|
|
9
|
+
::ActiveRecord::Base.send(:include, Validators)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Blogit::Parsers::MarkdownParser
|
|
2
|
+
|
|
3
|
+
require "nokogiri"
|
|
4
|
+
|
|
5
|
+
def initialize(content)
|
|
6
|
+
@content = content
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def parsed
|
|
10
|
+
Redcarpet.new(@content, *Blogit.configuration.redcarpet_options).to_html
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# def syntax_highlighter(html)
|
|
14
|
+
# doc = Nokogiri::HTML(html)
|
|
15
|
+
# doc.search("//pre[@lang]").each do |pre|
|
|
16
|
+
# pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
|
|
17
|
+
# end
|
|
18
|
+
# doc.to_s
|
|
19
|
+
# end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Blogit
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
desc "Creates a Blogit initializer in your application's config/initializers dir"
|
|
8
|
+
|
|
9
|
+
def copy_initializer
|
|
10
|
+
template "blogit.rb", "config/initializers/blogit.rb"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# These configuration options can be used to customise the behaviour of Blogit
|
|
2
|
+
Blogit.configure do |config|
|
|
3
|
+
|
|
4
|
+
# Do you want to add comments to your blog?
|
|
5
|
+
config.include_comments = true
|
|
6
|
+
|
|
7
|
+
# The name of the controller method we'll call to return the current blogger.
|
|
8
|
+
# Change this if you use something other than current_user.
|
|
9
|
+
# Eg. current_admin_user (if using ActiveAdmin)
|
|
10
|
+
config.current_blogger_method = :current_user
|
|
11
|
+
|
|
12
|
+
# What method do we call on blogger to show who they are?
|
|
13
|
+
config.blogger_display_name_method = :username
|
|
14
|
+
|
|
15
|
+
# Which DateTime::FORMATS format do we use to display blog and comment publish time
|
|
16
|
+
config.datetime_format = :short
|
|
17
|
+
|
|
18
|
+
# No. of posts to show per page
|
|
19
|
+
config.posts_per_page = 5
|
|
20
|
+
|
|
21
|
+
# The name of the before filter we'll call to authenticate the current user.
|
|
22
|
+
config.authentication_method = :login_required
|
|
23
|
+
|
|
24
|
+
# If set to true, the comments form will POST and DELETE to the comments
|
|
25
|
+
# controller using AJAX calls.
|
|
26
|
+
config.ajax_comments = true
|
|
27
|
+
|
|
28
|
+
# If set to true, the create, edit, update and destroy actions
|
|
29
|
+
# will be included. If set to false, you'll have to set these
|
|
30
|
+
# yourself elsewhere in the app.
|
|
31
|
+
# @note - This is not currently implemented
|
|
32
|
+
config.include_admin_actions = true
|
|
33
|
+
|
|
34
|
+
# The default format for parsing the blog content.
|
|
35
|
+
config.default_parser = :markdown
|
|
36
|
+
|
|
37
|
+
# When using redcarpet as content parser, pass these options as defaults.
|
|
38
|
+
# @see here for more options: https://github.com/tanoku/redcarpet
|
|
39
|
+
config.redcarpet_options = [:hard_wrap, :filter_html, :autolink,
|
|
40
|
+
:no_intraemphasis, :fenced_code, :gh_blockcode]
|
|
41
|
+
|
|
42
|
+
end
|
data/lib/validators.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Validators
|
|
2
|
+
|
|
3
|
+
# Checks that an attribute is absent.
|
|
4
|
+
# The opposite of PresenceValidator
|
|
5
|
+
class AbsenceValidator < ActiveModel::EachValidator
|
|
6
|
+
|
|
7
|
+
def validate_each(record, attribute, value)
|
|
8
|
+
record.errors.add(attribute, :invalid, options) unless value.blank?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
data/spec/blogit_spec.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Blogit do
|
|
4
|
+
|
|
5
|
+
it "should allow developers to set configurations with a block" do
|
|
6
|
+
initial_value = Blogit.configuration.current_blogger_method
|
|
7
|
+
Blogit.configure do |config|
|
|
8
|
+
config.current_blogger_method = :logged_in_user
|
|
9
|
+
end
|
|
10
|
+
user_set_value = Blogit.configuration.current_blogger_method
|
|
11
|
+
initial_value.should_not eql(user_set_value)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
after :all do
|
|
15
|
+
Blogit.configure do |config|
|
|
16
|
+
config.inspect
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CommentsController do
|
|
4
|
+
|
|
5
|
+
let(:blog_post) { Blogit::Post.first || create(:post) }
|
|
6
|
+
|
|
7
|
+
describe "POST create" do
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
@comment_attributes = attributes_for(:comment)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def do_post(format = :html)
|
|
14
|
+
post :create, post_id: blog_post.id,
|
|
15
|
+
comment: @comment_attributes, use_route: :blogit, format: format
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "whith JS" do
|
|
19
|
+
|
|
20
|
+
it "should persist comment" do
|
|
21
|
+
lambda { do_post(:js) }.should change { blog_post.comments.count }.by(1)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The rest is handled in the view
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "with HTML" do
|
|
29
|
+
|
|
30
|
+
it "should persist comment" do
|
|
31
|
+
lambda { do_post(:html) }.should change { blog_post.comments.count }.by(1)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should redirect to the blog post" do
|
|
35
|
+
do_post
|
|
36
|
+
response.should redirect_to(controller.post_url(blog_post))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should display a flash notice" do
|
|
40
|
+
do_post
|
|
41
|
+
flash[:notice].should be_present
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "DELETE destroy" do
|
|
49
|
+
|
|
50
|
+
def do_delete(format = :html)
|
|
51
|
+
delete :destroy, id: @comment.id,
|
|
52
|
+
post_id: blog_post.id, format: format, use_route: :blogit
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
before do
|
|
56
|
+
@comment = create(:comment, post: blog_post)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "when user logged in" do
|
|
60
|
+
|
|
61
|
+
before do
|
|
62
|
+
mock_login
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "whith JS" do
|
|
66
|
+
|
|
67
|
+
it "should destroy the comment" do
|
|
68
|
+
lambda { do_delete(:js) }.should change { blog_post.reload.comments.count }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe "with HTML" do
|
|
74
|
+
|
|
75
|
+
it "should destroy the comment" do
|
|
76
|
+
lambda { do_delete(:html) }.should change { blog_post.reload.comments.count }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should redirect to the blog post " do
|
|
80
|
+
do_delete
|
|
81
|
+
response.should redirect_to(controller.post_url(blog_post))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "when user is not logged in" do
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
describe "whith JS" do
|
|
92
|
+
|
|
93
|
+
it 'should not destroy the comment' do
|
|
94
|
+
lambda { do_delete }.should_not change { Comment.count }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "with HTML" do
|
|
100
|
+
|
|
101
|
+
it "should not destroy the comment" do
|
|
102
|
+
lambda { do_delete }.should_not change { Comment.count }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PostsController do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
reset_configuration
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:blog_post) { build :post }
|
|
10
|
+
|
|
11
|
+
describe "GET 'index'" do
|
|
12
|
+
|
|
13
|
+
let(:posts) { [] }
|
|
14
|
+
|
|
15
|
+
def do_get(page=nil)
|
|
16
|
+
get :index, :use_route => :blogit, page: page.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should set posts to Blogit::Post.for_index" do
|
|
20
|
+
Blogit::Post.expects(:for_index).returns(posts)
|
|
21
|
+
do_get
|
|
22
|
+
controller.posts.should == posts
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should pass the page param to for_index" do
|
|
26
|
+
Blogit::Post.expects(:for_index).with("2").returns(posts)
|
|
27
|
+
do_get("2")
|
|
28
|
+
controller.posts.should == posts
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "GET 'new'" do
|
|
34
|
+
|
|
35
|
+
context "when logged in" do
|
|
36
|
+
|
|
37
|
+
before do
|
|
38
|
+
mock_login
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def do_get
|
|
42
|
+
get :new, use_route: :blogit
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should be successful" do
|
|
46
|
+
do_get
|
|
47
|
+
response.should be_success
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should set post to a new blog post" do
|
|
51
|
+
do_get
|
|
52
|
+
controller.post.should be_a(Blogit::Post)
|
|
53
|
+
controller.post.should be_a_new_record
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when not logged in" do
|
|
59
|
+
|
|
60
|
+
def do_get
|
|
61
|
+
get :new, use_route: :blogit
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# It's not really the responsibility of the gem to manage authentication
|
|
65
|
+
# so testing for specific behaviour here is not required
|
|
66
|
+
# at the very least though, we'd expect the status not to be 200
|
|
67
|
+
it "should redirect to another page" do
|
|
68
|
+
do_get
|
|
69
|
+
response.should_not be_success
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "POST /create" do
|
|
76
|
+
|
|
77
|
+
context "when logged in" do
|
|
78
|
+
|
|
79
|
+
before do
|
|
80
|
+
mock_login
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "with valid params" do
|
|
84
|
+
|
|
85
|
+
let(:post_attributes) { attributes_for(:post) }
|
|
86
|
+
|
|
87
|
+
def do_post
|
|
88
|
+
post :create, use_route: :blogit, post: post_attributes
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
before do
|
|
92
|
+
@blog_posts = []
|
|
93
|
+
@current_blogger.expects(:blog_posts).returns(@blog_posts)
|
|
94
|
+
@blog_posts.expects(:new).with(post_attributes.stringify_keys).returns(blog_post)
|
|
95
|
+
blog_post.expects(:save).returns(true)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should redirect to the blog post page" do
|
|
99
|
+
do_post
|
|
100
|
+
response.should redirect_to(controller.posts_url)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
describe "GET 'edit'" do
|
|
111
|
+
|
|
112
|
+
context "when logged in" do
|
|
113
|
+
|
|
114
|
+
before do
|
|
115
|
+
mock_login
|
|
116
|
+
@current_blogger.expects(:blog_posts).returns(@blog_posts = [])
|
|
117
|
+
@blog_posts.expects(:find).with("1").returns(blog_post)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def do_get
|
|
121
|
+
get :edit, :id => 1, use_route: :blogit
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "should find the blog post by the ID" do
|
|
125
|
+
do_get
|
|
126
|
+
controller.post.should eql(blog_post)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "when not logged in" do
|
|
132
|
+
|
|
133
|
+
def do_get
|
|
134
|
+
get :edit, :id => 1, use_route: :blogit
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# It's not really the responsibility of the gem to manage authentication
|
|
138
|
+
# so testing for specific behaviour here is not required
|
|
139
|
+
# at the very least though, we'd expect the status not to be 200
|
|
140
|
+
it "should redirect to another pages" do
|
|
141
|
+
do_get
|
|
142
|
+
response.should_not be_success
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe "PUT 'update'" do
|
|
150
|
+
|
|
151
|
+
context "when logged in" do
|
|
152
|
+
|
|
153
|
+
before do
|
|
154
|
+
@post_attributes = { "title" => "Something new" }
|
|
155
|
+
mock_login
|
|
156
|
+
@current_blogger.expects(:blog_posts).returns(@blog_posts = [])
|
|
157
|
+
@blog_posts.expects(:find).with("1").returns(blog_post)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def do_put
|
|
161
|
+
put :update, id: "1", use_route: :blogit, post: @post_attributes
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should update the post attributes from params" do
|
|
165
|
+
blog_post.expects(:update_attributes).with(@post_attributes).returns(true)
|
|
166
|
+
do_put
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should redirect to the blog post page" do
|
|
170
|
+
do_put
|
|
171
|
+
response.should redirect_to(controller.post_url(blog_post))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should set a flash notice" do
|
|
175
|
+
do_put
|
|
176
|
+
flash[:notice].should be_present
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
context "when not logged in" do
|
|
181
|
+
|
|
182
|
+
before do
|
|
183
|
+
@post_attributes = { "title" => "Something new" }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def do_put
|
|
187
|
+
put :update, id: "1", use_route: :blogit, post: @post_attributes
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# It's not really the responsibility of the gem to manage authentication
|
|
191
|
+
# so testing for specific behaviour here is not required
|
|
192
|
+
# at the very least though, we'd expect the status not to be 200
|
|
193
|
+
it "should redirect to another page" do
|
|
194
|
+
do_put
|
|
195
|
+
response.should_not be_success
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "GET 'show'" do
|
|
203
|
+
|
|
204
|
+
before do
|
|
205
|
+
Blogit::Post.expects(:find).with("1").returns(blog_post)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def do_get
|
|
209
|
+
get :show, :id => 1, use_route: :blogit
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should find blog post by id" do
|
|
213
|
+
do_get
|
|
214
|
+
controller.post.should eql(blog_post)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
describe "DELETE 'destroy'" do
|
|
220
|
+
|
|
221
|
+
def do_delete
|
|
222
|
+
delete :destroy, id: "1", use_route: :blogit
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe "when logged in" do
|
|
226
|
+
|
|
227
|
+
before do
|
|
228
|
+
mock_login
|
|
229
|
+
@current_blogger.expects(:blog_posts).returns(@blog_posts = [])
|
|
230
|
+
@blog_posts.expects(:find).with("1").returns(blog_post)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "should destroy the blog post" do
|
|
234
|
+
blog_post.expects(:destroy)
|
|
235
|
+
do_delete
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "should redirect to the blog posts url" do
|
|
239
|
+
do_delete
|
|
240
|
+
response.should redirect_to(controller.posts_url)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it "should show a flash notice" do
|
|
244
|
+
do_delete
|
|
245
|
+
flash[:notice].should be_present
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
describe "when not logged in" do
|
|
251
|
+
|
|
252
|
+
it "should redirect to another page" do
|
|
253
|
+
do_delete
|
|
254
|
+
response.should_not be_success
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
end
|