blogit 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.md +11 -3
  2. data/app/assets/javascripts/blogit/archive.js +8 -0
  3. data/app/assets/javascripts/blogit/index.js +1 -1
  4. data/app/assets/stylesheets/blogit/index.css +10 -1
  5. data/app/controllers/blogit/comments_controller.rb +7 -7
  6. data/app/controllers/blogit/posts_controller.rb +12 -10
  7. data/app/helpers/blogit/application_helper.rb +23 -4
  8. data/app/helpers/blogit/posts_helper.rb +47 -3
  9. data/app/models/blogit/comment.rb +2 -0
  10. data/app/models/blogit/post.rb +26 -8
  11. data/app/views/blogit/comments/_admin_links.html.erb +2 -2
  12. data/app/views/blogit/comments/_comment.html.erb +8 -8
  13. data/app/views/blogit/comments/_form.html.erb +17 -18
  14. data/app/views/blogit/posts/_active_record_comments.html.erb +4 -0
  15. data/app/views/blogit/posts/_blogger_information.html.erb +1 -1
  16. data/app/views/blogit/posts/_comments_count.html.erb +2 -2
  17. data/app/views/blogit/posts/_disqus_comments.html.erb +14 -0
  18. data/app/views/blogit/posts/_empty.html.erb +2 -2
  19. data/app/views/blogit/posts/_form.html.erb +9 -9
  20. data/app/views/blogit/posts/_no_comments.html.erb +0 -0
  21. data/app/views/blogit/posts/_post.html.erb +6 -6
  22. data/app/views/blogit/posts/_post_links.html.erb +1 -1
  23. data/app/views/blogit/posts/_share_bar.html.erb +45 -0
  24. data/app/views/blogit/posts/edit.html.erb +2 -2
  25. data/app/views/blogit/posts/index.html.erb +7 -7
  26. data/app/views/blogit/posts/new.html.erb +1 -1
  27. data/app/views/blogit/posts/show.html.erb +2 -6
  28. data/config/locales/en.yml +48 -0
  29. data/config/locales/fr.yml +61 -0
  30. data/lib/blogit/configuration.rb +69 -30
  31. data/lib/blogit/version.rb +1 -1
  32. data/lib/generators/templates/blogit.rb +34 -18
  33. data/spec/controllers/blogit/posts_controller_spec.rb +75 -75
  34. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +8 -4
  36. data/spec/dummy/config/application.rb +1 -1
  37. data/spec/dummy/config/initializers/blogit.rb +21 -12
  38. data/spec/dummy/db/development.sqlite3 +0 -0
  39. data/spec/dummy/db/test.sqlite3 +0 -0
  40. data/spec/dummy/log/development.log +155 -0
  41. data/spec/dummy/log/test.log +7310 -0
  42. data/spec/helpers/blogit/application_helper_spec.rb +63 -8
  43. data/spec/helpers/blogit/posts_helper_spec.rb +114 -6
  44. data/spec/lib/blogit/parsers/markdown_parser_spec.rb +7 -3
  45. data/spec/lib/configuration_spec.rb +43 -19
  46. data/spec/models/blogit/post_spec.rb +51 -53
  47. data/spec/spec_helper.rb +1 -1
  48. metadata +158 -36
@@ -1,14 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Blogit::ApplicationHelper do
4
-
4
+
5
5
  describe "format_content" do
6
-
6
+
7
7
  it "should convert markdown text to html if conf is :markdown" do
8
8
  Blogit.configure { |c| c.default_parser = :markdown }
9
9
  helper.format_content("## Hello\n\nWorld").should match(/<h2>Hello<\/h2>\n\n<p>World<\/p>/)
10
10
  end
11
-
11
+
12
12
  it "should convert textile text to html if conf is :textile" do
13
13
  Blogit.configure { |c| c.default_parser = :textile }
14
14
  helper.format_content("h1. Hello\n\nWorld").should == "<h1>Hello</h1>\n<p>World</p>"
@@ -19,16 +19,71 @@ describe Blogit::ApplicationHelper do
19
19
  helper.format_content("<h1>Hello</h1>\n\n<p>World</p>").should == "<h1>Hello</h1>\n\n<p>World</p>"
20
20
  end
21
21
 
22
-
22
+
23
23
  end
24
-
24
+
25
25
  describe :actions do
26
-
26
+
27
27
  it "should create a div with class 'actions'" do
28
28
  helper.actions do
29
29
  "hello"
30
30
  end.should == %{<div class="actions">hello</div>}
31
31
  end
32
-
32
+
33
+ end
34
+
35
+ describe "main app's named routes" do
36
+
37
+
38
+ # rspec generates a helper by mixin in the tested helper and the application
39
+ # helper. But this is not what is being done by rails inside an engine.
40
+ # This mockery is more like the real thing
41
+ class MainAppApplicationHelperBench
42
+ def dummy_thing_path
43
+ "/dummy_thing"
44
+ end
45
+ def dummy_thing_url
46
+ "http://host/dummy_thing"
47
+ end
48
+ def secret
49
+ end
50
+ end
51
+ class BlogitApplicationHelperBench
52
+ include Blogit::ApplicationHelper
53
+
54
+ def main_app
55
+ MainAppApplicationHelperBench.new
56
+ end
57
+ end
58
+
59
+ let(:raw_helper) { BlogitApplicationHelperBench.new }
60
+
61
+ it "should not know named routes of the main app if not configured" do
62
+ Blogit.configure {|c| c.inline_main_app_named_routes = false }
63
+
64
+ lambda { raw_helper.dummy_thing_path }.should raise_error(NoMethodError)
65
+ lambda { raw_helper.dummy_thing_url }.should raise_error(NoMethodError)
66
+ end
67
+
68
+ it "should know named routes of the main app" do
69
+ Blogit.configure {|c| c.inline_main_app_named_routes = true }
70
+
71
+ raw_helper.dummy_thing_path.should == "/dummy_thing"
72
+ raw_helper.dummy_thing_url.should == "http://host/dummy_thing"
73
+ end
74
+
75
+ it "should not know anything but named routes of the main app" do
76
+ Blogit.configure {|c| c.inline_main_app_named_routes = true }
77
+
78
+ lambda { raw_helper.secret }.should raise_error(NoMethodError)
79
+ end
80
+
81
+ it "should not know other routes" do
82
+ Blogit.configure {|c| c.inline_main_app_named_routes = true }
83
+
84
+ lambda { raw_helper.junk_path }.should raise_error(NoMethodError)
85
+ lambda { raw_helper.junk_url }.should raise_error(NoMethodError)
86
+ end
87
+
33
88
  end
34
- end
89
+ end
@@ -1,14 +1,122 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require "spec_helper"
2
3
 
3
4
  describe Blogit::PostsHelper do
4
-
5
+
5
6
  describe :blog_post_tag do
6
-
7
+
7
8
  it "should create a tag element and give it a 'blog_post... prefixed class" do
8
9
  helper.blog_post_tag(:div, "hello", id: "blog_div", class: "other_class").should == %{<div class="other_class blog_post_div" id="blog_div">hello</div>}
9
- helper.blog_post_tag(:li, "hello", id: "blog_li").should == %{<li class="blog_post_li" id="blog_li">hello</li>}
10
+ helper.blog_post_tag(:li, "hello", id: "blog_li").should == %{<li class="blog_post_li" id="blog_li">hello</li>}
11
+ end
12
+
13
+ end
14
+
15
+ describe :comments_for do
16
+ let(:post) { FactoryGirl.create :post }
17
+
18
+ it "should be empty if comments are not configured" do
19
+ Blogit.configure do |config|
20
+ config.include_comments = :no
21
+ end
22
+
23
+ helper.comments_for(post).should == ""
24
+ end
25
+
26
+ it "should be full html when comments use active record" do
27
+ Blogit.configure do |config|
28
+ config.include_comments = :active_record
29
+ end
30
+
31
+ comment = Blogit::Comment.new
32
+ Blogit::Comment.expects(:new).returns(comment)
33
+ helper.expects(:render).with(partial: "blogit/posts/active_record_comments", locals: {post: post, comment: comment})
34
+ helper.comments_for(post)
35
+ end
36
+ end
37
+
38
+ describe :share_bar_for do
39
+ let(:post) { FactoryGirl.create :post }
40
+
41
+ it "should be empty if not configured" do
42
+ Blogit.configure do |config|
43
+ config.include_share_bar = false
44
+ end
45
+
46
+ helper.share_bar_for(post).should == ""
47
+ end
48
+
49
+ it "should render a share bar if configured" do
50
+ Blogit.configure do |config|
51
+ config.include_share_bar = true
52
+ end
53
+
54
+ helper.expects(:render).with(partial: "blogit/posts/share_bar", locals: {post: post}).returns(share_bar_html='<div id="share-bar">...</div>')
55
+ helper.share_bar_for(post).should == share_bar_html
10
56
  end
11
-
12
57
  end
13
-
14
- end
58
+
59
+ describe :blog_post_archive do
60
+
61
+ before :each do
62
+ Post.delete_all
63
+ end
64
+ after :each do
65
+ Post.delete_all
66
+ end
67
+
68
+
69
+ it "should create an ul tag tree with years, monthes and articles" do
70
+ dec_2011 = FactoryGirl.create(:post, title: "Great post 1", created_at: Time.new(2011, 12, 25))
71
+ july_2012_1 = FactoryGirl.create(:post, title: "Great Post 2", created_at: Time.new(2012,7,14))
72
+ july_2012_2 = FactoryGirl.create(:post, title: "Great Post 3", created_at: Time.new(2012,7,28))
73
+ sept_2012 = FactoryGirl.create(:post, title: "Great Post 4", created_at: Time.new(2012,9, 3))
74
+
75
+ year_css = "archive-years"
76
+ month_css = "archive-month"
77
+ post_css = "archive-post"
78
+
79
+ helper.blog_posts_archive_tag(year_css, month_css, post_css).should == ["<ul class=\"#{year_css}\">",
80
+ "<li><a onclick=\"toggleBrothersDisplay(this, 'UL')\">2011</a>",
81
+ "<ul class=\"#{month_css}\">",
82
+ "<li><a onclick=\"toggleBrothersDisplay(this, 'UL')\">December</a>",
83
+ "<ul class=\"#{post_css}\">",
84
+ "<li><a href=\"#{blogit.post_path(dec_2011)}\">#{dec_2011.title}</a></li>",
85
+ "</ul>",
86
+ "</li>",
87
+ "</ul>",
88
+ "</li>",
89
+ "<li><a onclick=\"toggleBrothersDisplay(this, 'UL')\">2012</a>",
90
+ "<ul class=\"#{month_css}\">",
91
+ "<li><a onclick=\"toggleBrothersDisplay(this, 'UL')\">July</a>",
92
+ "<ul class=\"#{post_css}\">",
93
+ "<li><a href=\"#{blogit.post_path(july_2012_1)}\">#{july_2012_1.title}</a></li>",
94
+ "<li><a href=\"#{blogit.post_path(july_2012_2)}\">#{july_2012_2.title}</a></li>",
95
+ "</ul>",
96
+ "</li>",
97
+ "<li><a onclick=\"toggleBrothersDisplay(this, 'UL')\">September</a>",
98
+ "<ul class=\"#{post_css}\">",
99
+ "<li><a href=\"#{blogit.post_path(sept_2012)}\">#{sept_2012.title}</a></li>",
100
+ "</ul>",
101
+ "</li>",
102
+ "</ul>",
103
+ "</li>",
104
+ "</ul>"].join
105
+ end
106
+
107
+ it "should escape html in titles" do
108
+ post = FactoryGirl.create(:post, title: ">Great Post with html characters<", created_at: Time.new(2012,9, 3))
109
+
110
+ archive_tag = helper.blog_posts_archive_tag('y','m','p')
111
+
112
+ archive_tag.should_not include(post.title)
113
+ archive_tag.should include(CGI.escape_html(post.title))
114
+ end
115
+
116
+ it "should be a safe html string" do
117
+ helper.blog_posts_archive_tag('y','m','p').should be_html_safe
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -11,13 +11,17 @@ describe Blogit::Parsers::MarkdownParser do
11
11
 
12
12
  describe "code highlighting" do
13
13
 
14
- let(:parser) {
15
- Blogit::Parsers::MarkdownParser.new("## Header\n\n``` ruby\nputs 'hello world'\n```")
14
+ let(:parser) {
15
+ Blogit::Parsers::MarkdownParser.new("## Header\n\n``` ruby\nputs 'hello world'\n```")
16
16
  }
17
17
 
18
+ it "requires pymentize to run" do
19
+ system("pygmentize > /dev/null").should equal(true), "It seems that pygmentize is not installed on your system"
20
+ end
21
+
18
22
  it "should highlight code if highlight_code_syntax is true" do
19
23
  Blogit::configuration.highlight_code_syntax = true
20
- parser.parsed.should =~
24
+ parser.parsed.should =~
21
25
  Regexp.new("<h2>Header</h2>\n<div class=\"highlight\"><pre><span class=\"nb\">puts</span> <span class=\"s1\">&#39;hello world&#39;</span>\n</pre>\n</div>\n")
22
26
  end
23
27
 
@@ -1,41 +1,65 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Blogit::Configuration do
4
-
4
+
5
5
  let(:blog_configuration) { @blog_configuration = Blogit::Configuration.new }
6
+
7
+ it "should set :include_comments to :active_record" do
8
+ blog_configuration.include_comments.should == :active_record
9
+ end
10
+
11
+ it "should set :disqus_shortname to blank" do
12
+ blog_configuration.disqus_shortname.should == ""
13
+ end
6
14
 
7
- it "should set :include_comments to true" do
8
- blog_configuration.include_comments.should be_true
15
+ it "should print a warning to the console if disqus_shortname is set but include_comments is not disqus" do
16
+ blog_configuration.expects(:warn)
17
+ blog_configuration.include_comments = :active_record
18
+ blog_configuration.disqus_shortname = "bodacious"
19
+ end
20
+
21
+ it "should print a warning to the console if twitter_username is set but include_share_bar is false" do
22
+ blog_configuration.expects(:warn)
23
+ blog_configuration.include_share_bar = true
24
+ blog_configuration.twitter_username = "bodacious"
25
+ end
26
+
27
+ it "should set :include_share_bar to false" do
28
+ blog_configuration.include_share_bar.should == false
29
+ end
30
+
31
+ it "should set :twitter_username to blank" do
32
+ blog_configuration.twitter_username.should == ""
9
33
  end
10
34
 
11
35
  it "should set :current_blogger_method to :current_user" do
12
36
  blog_configuration.current_blogger_method.should eql(:current_user)
13
37
  end
14
-
38
+
15
39
  it "should set :blogger_display_name_method to :username" do
16
40
  blog_configuration.blogger_display_name_method.should eql(:username)
17
41
  end
18
-
42
+
19
43
  it "should set :posts_per_page to 5" do
20
44
  blog_configuration.posts_per_page.should eql(5)
21
45
  end
22
-
46
+
23
47
  it "should set :authentication_method to :login_required" do
24
48
  blog_configuration.authentication_method.should == :login_required
25
49
  end
26
-
50
+
27
51
  it "should set datetime format to :short" do
28
52
  blog_configuration.datetime_format.should == :short
29
53
  end
30
-
54
+
31
55
  it "should set author_edits_only to false" do
32
56
  blog_configuration.author_edits_only.should be_false
33
57
  end
34
-
58
+
35
59
  it "should set ajax comments to true" do
36
60
  blog_configuration.ajax_comments.should be_true
37
61
  end
38
-
62
+
39
63
  it "should set include admin actions to true" do
40
64
  blog_configuration.include_admin_actions.should be_true
41
65
  end
@@ -43,7 +67,7 @@ describe Blogit::Configuration do
43
67
  it "should set include admin links to true" do
44
68
  blog_configuration.include_admin_links.should be_true
45
69
  end
46
-
70
+
47
71
  it "should set page caching to false by default" do
48
72
  blog_configuration.cache_pages.should be_false
49
73
  end
@@ -51,14 +75,14 @@ describe Blogit::Configuration do
51
75
  it "should set default_parser to :markdown" do
52
76
  blog_configuration.default_parser.should eql(:markdown)
53
77
  end
54
-
78
+
55
79
  it "should return default_parser as class with default_parser_class" do
56
80
  blog_configuration.default_parser = :textile
57
81
  blog_configuration.default_parser_class.should eql(Blogit::Parsers::TextileParser)
58
82
  end
59
-
83
+
60
84
  it "should set redcarpet default options" do
61
- blog_configuration.redcarpet_options.should ==
85
+ blog_configuration.redcarpet_options.should ==
62
86
  {
63
87
  hard_wrap: true,
64
88
  filter_html: true,
@@ -68,15 +92,15 @@ describe Blogit::Configuration do
68
92
  gh_blockcode: true
69
93
  }
70
94
  end
71
-
95
+
72
96
  it "should set highlight_code_syntax to true" do
73
97
  blog_configuration.highlight_code_syntax.should be_true
74
98
  end
75
-
99
+
76
100
  it "should set rss_feed_title to 'Rails engine name Blog Posts'" do
77
101
  blog_configuration.rss_feed_title.should eql "#{Rails.application.engine_name.titleize} Blog Posts"
78
102
  end
79
-
103
+
80
104
  it "should set rss_feed_description to 'Rails engine name Blog Posts'" do
81
105
  blog_configuration.rss_feed_description.should eql "#{Rails.application.engine_name.titleize} Blog Posts"
82
106
  end
@@ -84,5 +108,5 @@ describe Blogit::Configuration do
84
108
  it "should set rss_feed_language to 'Rails engine name Blog Posts'" do
85
109
  blog_configuration.rss_feed_language.should eql "en"
86
110
  end
87
-
88
- end
111
+
112
+ end
@@ -1,19 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Blogit::Post do
4
-
4
+
5
5
  context "should not be valid" do
6
-
6
+
7
7
  context "if blogger" do
8
-
8
+
9
9
  it "is nil" do
10
10
  @blog_post = Blogit::Post.new
11
11
  @blog_post.should_not be_valid
12
12
  @blog_post.should have(1).error_on(:blogger_id)
13
13
  end
14
-
14
+
15
15
  end
16
-
16
+
17
17
  context "if title" do
18
18
  before do
19
19
  @blog_post = Blogit::Post.new
@@ -35,9 +35,9 @@ describe Blogit::Post do
35
35
  it "is longer than 66 characters" do
36
36
  @blog_post.title = "a" * 67
37
37
  end
38
-
38
+
39
39
  end
40
-
40
+
41
41
  context "if body" do
42
42
  before do
43
43
  @blog_post = Blogit::Post.new
@@ -47,47 +47,47 @@ describe Blogit::Post do
47
47
  @blog_post.should_not be_valid
48
48
  @blog_post.errors[:body].should_not be_blank
49
49
  end
50
-
50
+
51
51
  it "is blank" do
52
52
  # defined above
53
53
  end
54
-
54
+
55
55
  it "is shorter than 10 characters" do
56
56
  @blog_post.body = "a" * 9
57
57
  end
58
-
58
+
59
59
  end
60
-
60
+
61
61
  end
62
-
63
- context "with Blogit.configuration.comments == true" do
64
- it "should have many comments if " do
62
+
63
+ context "with Blogit.configuration.comments == active_record" do
64
+ it "should allow comments" do
65
65
  Blogit.configure do |config|
66
- # this should be true by default anyway
67
- config.include_comments = true
66
+ # this should be :active_record by default anyway
67
+ config.include_comments = :active_record
68
68
  end
69
69
  User.blogs
70
70
  @blog_post = Blogit::Post.new
71
- lambda { @blog_post.comments }.should_not raise_exception(NoMethodError)
71
+ lambda { @blog_post.comments }.should_not raise_exception(RuntimeError)
72
72
  end
73
-
73
+
74
74
  end
75
-
75
+
76
76
  describe "blogger_display_name" do
77
-
77
+
78
78
  before :all do
79
79
  User.blogs
80
80
  end
81
-
81
+
82
82
  let(:user) { User.create! username: "Jeronimo", password: "password" }
83
-
83
+
84
84
  it "should return the display name of the blogger if set" do
85
85
  @post = user.blog_posts.build
86
86
  @post.blogger_display_name.should == "Jeronimo"
87
87
  Blogit.configuration.blogger_display_name_method = :password
88
88
  @post.blogger_display_name.should == "password"
89
89
  end
90
-
90
+
91
91
  it "should return an empty string if blogger doesn't exist" do
92
92
  Blogit.configuration.blogger_display_name_method = :username
93
93
  @post = Blogit::Post.new
@@ -99,55 +99,53 @@ describe Blogit::Post do
99
99
  @post = user.blog_posts.build
100
100
  lambda { @post.blogger_display_name }.should raise_exception(Blogit::ConfigurationError)
101
101
  end
102
-
102
+
103
103
  end
104
-
104
+
105
105
  describe "scopes" do
106
-
106
+
107
107
  describe :for_index do
108
-
108
+
109
109
  before :all do
110
110
  Blogit::Post.destroy_all
111
111
  15.times { |i| create :post, created_at: i.days.ago }
112
112
  end
113
-
113
+
114
114
  it "should order posts by created_at DESC" do
115
115
  Blogit::Post.for_index.first.should == Blogit::Post.order("created_at DESC").first
116
116
  end
117
-
117
+
118
118
  it "should paginate posts in blocks of 5" do
119
119
  Blogit::Post.for_index.count.should == 5
120
120
  end
121
-
121
+
122
122
  it "should accept page no as an argument" do
123
123
  Blogit::Post.for_index(2).should == Blogit::Post.order("created_at DESC").offset(5).limit(5)
124
124
  end
125
-
125
+
126
126
  it "should change the no of posts per page if paginates_per is set" do
127
127
  Blogit::Post.paginates_per 3
128
128
  Blogit::Post.for_index.count.should eql(3)
129
129
  end
130
-
131
-
130
+
131
+
132
+ end
133
+
134
+
135
+ end
136
+
137
+
138
+ describe "with Blogit.configuration.comments != active_record" do
139
+
140
+ it "should not allow comments" do
141
+ Blogit.configure do |config|
142
+ config.include_comments = :no
143
+ end
144
+ User.blogs
145
+ @blog_post = Blogit::Post.new
146
+ lambda { @blog_post.comments }.should raise_exception(RuntimeError)
132
147
  end
133
-
134
-
148
+
135
149
  end
136
-
137
-
138
- # TODO: Find a better way to test this
139
- # describe "with Blogit.configuration.comments == false" do
140
- #
141
- # it "should not have many comments if Blogit.configuration.comments == false" do
142
- # Blogit.configure do |config|
143
- # # this should be true by default anyway
144
- # config.include_comments = false
145
- # end
146
- # User.blogs
147
- # @blog_post = Blogit::Post.new
148
- # lambda { @blog_post.comments }.should raise_exception(NoMethodError)
149
- # end
150
- #
151
- # end
152
-
153
- end
150
+
151
+ end