buttercms 0.2.2 → 0.2.3

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Rakefile +37 -1
  4. data/app/controllers/buttercms/blog_controller.rb +33 -25
  5. data/buttercms.gemspec +2 -0
  6. data/lib/buttercms/version.rb +1 -1
  7. data/test/buttercms_test.rb +204 -4
  8. data/test/dummy/README.rdoc +28 -0
  9. data/test/dummy/Rakefile +6 -0
  10. data/test/dummy/app/assets/images/.keep +0 -0
  11. data/test/dummy/app/assets/javascripts/application.js +13 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  13. data/test/dummy/app/controllers/application_controller.rb +5 -0
  14. data/test/dummy/app/controllers/concerns/.keep +0 -0
  15. data/test/dummy/app/helpers/application_helper.rb +5 -0
  16. data/test/dummy/app/mailers/.keep +0 -0
  17. data/test/dummy/app/models/.keep +0 -0
  18. data/test/dummy/app/models/concerns/.keep +0 -0
  19. data/test/dummy/app/views/blog/_pagers.html.erb +13 -0
  20. data/test/dummy/app/views/blog/_post.html.erb +22 -0
  21. data/test/dummy/app/views/blog/author.html.erb +3 -0
  22. data/test/dummy/app/views/blog/category.html.erb +3 -0
  23. data/test/dummy/app/views/blog/home.html.erb +5 -0
  24. data/test/dummy/app/views/blog/post.html.erb +76 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/bin/bundle +3 -0
  27. data/test/dummy/bin/rails +4 -0
  28. data/test/dummy/bin/rake +4 -0
  29. data/test/dummy/bin/setup +29 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/config/application.rb +26 -0
  32. data/test/dummy/config/boot.rb +5 -0
  33. data/test/dummy/config/database.yml +25 -0
  34. data/test/dummy/config/environment.rb +5 -0
  35. data/test/dummy/config/environments/development.rb +41 -0
  36. data/test/dummy/config/environments/production.rb +79 -0
  37. data/test/dummy/config/environments/test.rb +42 -0
  38. data/test/dummy/config/initializers/assets.rb +11 -0
  39. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/test/dummy/config/initializers/butter.rb +13 -0
  41. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  42. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/test/dummy/config/initializers/inflections.rb +16 -0
  44. data/test/dummy/config/initializers/mime_types.rb +4 -0
  45. data/test/dummy/config/initializers/session_store.rb +3 -0
  46. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/test/dummy/config/locales/en.yml +23 -0
  48. data/test/dummy/config/routes.rb +4 -0
  49. data/test/dummy/config/secrets.yml +22 -0
  50. data/test/dummy/db/test.sqlite3 +0 -0
  51. data/test/dummy/lib/assets/.keep +0 -0
  52. data/test/dummy/log/.keep +0 -0
  53. data/test/dummy/public/404.html +67 -0
  54. data/test/dummy/public/422.html +67 -0
  55. data/test/dummy/public/500.html +66 -0
  56. data/test/dummy/public/favicon.ico +0 -0
  57. metadata +130 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2eef23f799e7a261812947a3943864262da177f
4
- data.tar.gz: 005f028b3d6c2faff3ca130fa84b795f0ea5709d
3
+ metadata.gz: cb1cc49cec49263c6cc7235b04bd6374e0b71ed3
4
+ data.tar.gz: e58a86c5bba9639451a2506ebf9104b5de94df0d
5
5
  SHA512:
6
- metadata.gz: 1c554e5c945396a62caf280637f1735d0d2f496d6676c453f5c97baa4a55e93f066e8c96efc9b948903e645b4ec7cef7e3835a505e0c6ed97bd1e2297d82b76b
7
- data.tar.gz: a480d3f73e3739233c180e6485eb6302df5bf7c40519d43fcfe4d6b1922eb369ddf32075f0a2d16451e019732a4dda3d20fe48d17293527e8b63715469ee6fa3
6
+ metadata.gz: c4ff507582245843ff9f4ef7791aca1a9e1a1e570e7e1a392132055c8079cd96998699874dd6adcb79b3ae0c0a57fd47b6297bc7d771a08e25b5c11447349b50
7
+ data.tar.gz: 2a677b384a44964f6e86112a8daef94e99e670027bdcff04734fdc07ad9a3fa7d98f92aa9d837c230bdc22e30fd4ec8977779af510197eac18e06dda8c3a73ac
data/.gitignore CHANGED
@@ -36,3 +36,7 @@ pkg/*
36
36
  *.log
37
37
 
38
38
  .DS_Store
39
+
40
+
41
+ test/dummy/tmp/
42
+ test/dummy/db/development.sqlite3
data/Rakefile CHANGED
@@ -1 +1,37 @@
1
- require "bundler/gem_tasks"
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Buttercms'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -1,47 +1,36 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
3
 
4
-
5
4
  module Buttercms
6
5
 
7
- API_URL = 'https://buttercms.com/api/'
8
-
9
6
  class Error < StandardError
10
7
  end
11
8
 
9
+
12
10
  class ConnectionError < Error
13
11
  def message
14
12
  "Unable to connect to ButterCms. Please double check your internet connection."
15
13
  end
16
14
  end
17
15
 
16
+
18
17
  class TokenError < Error
19
18
  def message
20
19
  "This token has not been registered. Please register one @ https://buttercms.com/api_token/"
21
20
  end
22
21
  end
23
22
 
23
+
24
24
  class InvalidResponseError < Error
25
25
  def message
26
26
  "An error occured retrieving blog. Please try again later."
27
27
  end
28
28
  end
29
29
 
30
- class BlogController < ApplicationController
31
- layout :get_butter_layout
32
- helper Rails.application.helpers
33
- helper Buttercms::ApplicationHelper
34
-
35
- def get_butter_layout
36
- if defined? Buttercms.configuration
37
- if !Buttercms.configuration.layout.nil?
38
- return Buttercms.configuration.layout
39
- end
40
- end
41
30
 
42
- # Default to the included layout.
43
- return "buttercms/application"
44
- end
31
+ # Thin wrapper around RestClient for talking to Butter API
32
+ module API
33
+ API_URL = 'https://buttercms.com/api/'
45
34
 
46
35
  def butter_not_found
47
36
  raise ActionController::RoutingError.new('Not Found')
@@ -62,7 +51,7 @@ module Buttercms
62
51
  begin
63
52
  # Get the content. If it takes longer than 10 seconds timeout.
64
53
  # TODO(jlumetta): Make :timeout configurable.
65
- response = RestClient.get path, {:Authorization => "Token #{get_butter_token}", :timeout => 10}
54
+ response = RestClient.get "#{API_URL}#{path}", {:Authorization => "Token #{get_butter_token}", :timeout => 10}
66
55
  rescue SocketError => e
67
56
  raise Buttercms::ConnectionError
68
57
  rescue => e
@@ -77,9 +66,28 @@ module Buttercms
77
66
  raise Buttercms::InvalidResponseError
78
67
  end
79
68
  end
80
-
81
69
  return response
82
70
  end
71
+ end
72
+
73
+
74
+ class BlogController < ApplicationController
75
+ include Buttercms::API
76
+
77
+ layout :get_butter_layout
78
+ helper Rails.application.helpers
79
+ helper Buttercms::ApplicationHelper
80
+
81
+ def get_butter_layout
82
+ if defined? Buttercms.configuration
83
+ if !Buttercms.configuration.layout.nil?
84
+ return Buttercms.configuration.layout
85
+ end
86
+ end
87
+
88
+ # Default to the included layout.
89
+ return "buttercms/application"
90
+ end
83
91
 
84
92
  def butter_home
85
93
  # Check for pagination
@@ -89,7 +97,7 @@ module Buttercms
89
97
  page_param = ''
90
98
  end
91
99
 
92
- response = make_butter_request("#{API_URL}posts/#{page_param}")
100
+ response = make_butter_request("posts/#{page_param}")
93
101
  response_json = JSON.parse(response)
94
102
  @next_page = response_json['next_page']
95
103
  @previous_page = response_json['previous_page']
@@ -99,14 +107,14 @@ module Buttercms
99
107
  end
100
108
 
101
109
  def butter_post
102
- response = make_butter_request("#{API_URL}posts/#{params[:slug]}")
110
+ response = make_butter_request("posts/#{params[:slug]}")
103
111
  @post = JSON.parse(response)
104
112
 
105
113
  render template: "blog/post"
106
114
  end
107
115
 
108
116
  def butter_author
109
- response = make_butter_request("#{API_URL}authors/#{params[:author_slug]}")
117
+ response = make_butter_request("authors/#{params[:author_slug]}")
110
118
  response_json = JSON.parse(response)
111
119
  @first_name = response_json['first_name']
112
120
  @last_name = response_json['last_name']
@@ -117,7 +125,7 @@ module Buttercms
117
125
  end
118
126
 
119
127
  def butter_category
120
- response = make_butter_request("#{API_URL}categories/#{params[:category_slug]}")
128
+ response = make_butter_request("categories/#{params[:category_slug]}")
121
129
  response_json = JSON.parse(response)
122
130
  @name = response_json['name']
123
131
  @recent_posts = response_json['recent_posts']
@@ -127,7 +135,7 @@ module Buttercms
127
135
 
128
136
 
129
137
  def butter_feed
130
- response = make_butter_request("#{API_URL}posts/")
138
+ response = make_butter_request("posts/")
131
139
  response_json = JSON.parse(response)
132
140
  @recent_posts = response_json['results']
133
141
  respond_to do |format|
@@ -137,7 +145,7 @@ module Buttercms
137
145
  end
138
146
 
139
147
  def butter_sitemap
140
- response = make_butter_request("#{API_URL}sitemap/")
148
+ response = make_butter_request("sitemap/")
141
149
  response_json = JSON.parse(response)
142
150
  @recent_posts = response_json
143
151
  end
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.7"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rails", "~> 4.2.1"
29
+ spec.add_development_dependency "sqlite3"
28
30
  end
@@ -1,3 +1,3 @@
1
1
  module Buttercms
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -1,7 +1,207 @@
1
1
  require 'test_helper'
2
+ require 'rest-client'
2
3
 
3
- class ButtercmsTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Buttercms
4
+ module Buttercms
5
+ class ButtercmsApiTest < ActiveSupport::TestCase
6
+ API_URL = 'https://buttercms.com/api/'
7
+ TEST_TOKEN = '6e9f14b48892b00079604c24c7c64a6a987456cf'
8
+
9
+ test "truth" do
10
+ assert_kind_of Module, Buttercms
11
+ end
12
+
13
+ test "API returns list of most recent posts in expected format" do
14
+ response = RestClient.get "#{API_URL}posts/", {:Authorization => "Token #{TEST_TOKEN}", :timeout => 10}
15
+ response_json = JSON.parse(response)
16
+
17
+ # Test the top level JSON structure
18
+ assert_equal response_json['next_page'], nil
19
+ assert_equal response_json['previous_page'], nil
20
+ assert_equal response_json['results'].length, 1
21
+
22
+ # Test the JSON structure of the post itself.
23
+ post = response_json['results'][0]
24
+ assert_equal post['id'], 101
25
+ assert_equal post['url'], 'http://www.example.com/blog/this-is-a-blog-post'
26
+ assert_equal post['created'], '06/12/2015'
27
+ assert_equal post['published'], '06/12/2015'
28
+ assert_equal post['slug'], 'this-is-a-blog-post'
29
+ assert_equal post['title'], 'This is a blog post'
30
+ assert_equal post['body'], '<p class="">This is a blog post to test the API.</p>'
31
+ assert_equal post['summary'], 'This is a blog post to test the API.'
32
+ assert_equal post['featured_image'], ''
33
+ assert_equal post['status'], 'published'
34
+
35
+ author = post['author']
36
+ assert_equal author['first_name'], 'API'
37
+ assert_equal author['last_name'], 'Test'
38
+ assert_equal author['email'], 'apitest@buttercms.com'
39
+ assert_equal author['slug'], 'api-test'
40
+
41
+ categories = post['categories']
42
+ assert_equal categories.length, 1
43
+ assert_equal categories[0]['name'], 'test category'
44
+ assert_equal categories[0]['slug'], 'test-category'
45
+ end
46
+
47
+ test "API returns details for a specific post based on slug" do
48
+ response = RestClient.get "#{API_URL}posts/this-is-a-blog-post", {:Authorization => "Token #{TEST_TOKEN}", :timeout => 10}
49
+ response_json = JSON.parse(response)
50
+
51
+ # Test the JSON structure of the post itself and ensure it's at the top level of the response body.
52
+ post = response_json
53
+ assert_equal post['id'], 101
54
+ assert_equal post['url'], 'http://www.example.com/blog/this-is-a-blog-post'
55
+ assert_equal post['created'], '06/12/2015'
56
+ assert_equal post['published'], '06/12/2015'
57
+ assert_equal post['slug'], 'this-is-a-blog-post'
58
+ assert_equal post['title'], 'This is a blog post'
59
+ assert_equal post['body'], '<p class="">This is a blog post to test the API.</p>'
60
+ assert_equal post['summary'], 'This is a blog post to test the API.'
61
+ assert_equal post['featured_image'], ''
62
+ assert_equal post['status'], 'published'
63
+
64
+ author = post['author']
65
+ assert_equal author['first_name'], 'API'
66
+ assert_equal author['last_name'], 'Test'
67
+ assert_equal author['email'], 'apitest@buttercms.com'
68
+ assert_equal author['slug'], 'api-test'
69
+
70
+ categories = post['categories']
71
+ assert_equal categories.length, 1
72
+ assert_equal categories[0]['name'], 'test category'
73
+ assert_equal categories[0]['slug'], 'test-category'
74
+ end
75
+
76
+
77
+ test "API returns details for a specific author based on slug" do
78
+ response = RestClient.get "#{API_URL}authors/api-test", {:Authorization => "Token #{TEST_TOKEN}", :timeout => 10}
79
+ response_json = JSON.parse(response)
80
+
81
+ # Ensure the author information is at the top level of the response.
82
+ author = response_json
83
+ assert_equal author['first_name'], 'API'
84
+ assert_equal author['last_name'], 'Test'
85
+ assert_equal author['email'], 'apitest@buttercms.com'
86
+ assert_equal author['slug'], 'api-test'
87
+
88
+ # Ensure we get all of their posts in the format we expect.
89
+ recent_posts = author['recent_posts']
90
+ assert_equal recent_posts.length, 1
91
+
92
+ post = recent_posts[0]
93
+ assert_equal post['id'], 101
94
+ assert_equal post['url'], 'http://www.example.com/blog/this-is-a-blog-post'
95
+ assert_equal post['created'], '06/12/2015'
96
+ assert_equal post['published'], '06/12/2015'
97
+ assert_equal post['slug'], 'this-is-a-blog-post'
98
+ assert_equal post['title'], 'This is a blog post'
99
+ assert_equal post['body'], '<p class="">This is a blog post to test the API.</p>'
100
+ assert_equal post['summary'], 'This is a blog post to test the API.'
101
+ assert_equal post['featured_image'], ''
102
+ assert_equal post['status'], 'published'
103
+
104
+ categories = post['categories']
105
+ assert_equal categories.length, 1
106
+ assert_equal categories[0]['name'], 'test category'
107
+ assert_equal categories[0]['slug'], 'test-category'
108
+ end
109
+
110
+ test "API returns details for a specific category based on slug" do
111
+ response = RestClient.get "#{API_URL}categories/test-category", {:Authorization => "Token #{TEST_TOKEN}", :timeout => 10}
112
+ response_json = JSON.parse(response)
113
+
114
+ # Ensure the author information is at the top level of the response.
115
+ category = response_json
116
+ assert_equal category['name'], 'test category'
117
+ assert_equal category['slug'], 'test-category'
118
+
119
+ # Ensure we get all of their posts in the format we expect.
120
+ recent_posts = category['recent_posts']
121
+ assert_equal recent_posts.length, 1
122
+
123
+ post = recent_posts[0]
124
+ assert_equal post['id'], 101
125
+ assert_equal post['url'], 'http://www.example.com/blog/this-is-a-blog-post'
126
+ assert_equal post['created'], '06/12/2015'
127
+ assert_equal post['published'], '06/12/2015'
128
+ assert_equal post['slug'], 'this-is-a-blog-post'
129
+ assert_equal post['title'], 'This is a blog post'
130
+ assert_equal post['body'], '<p class="">This is a blog post to test the API.</p>'
131
+ assert_equal post['summary'], 'This is a blog post to test the API.'
132
+ assert_equal post['featured_image'], ''
133
+ assert_equal post['status'], 'published'
134
+ end
135
+
136
+ test "API returns sitemap for blog" do
137
+ response = RestClient.get "#{API_URL}sitemap", {:Authorization => "Token #{TEST_TOKEN}", :timeout => 10}
138
+ response_json = JSON.parse(response)
139
+
140
+ assert_equal response_json.length, 1
141
+
142
+ sitemap_entry = response_json[0]
143
+ assert_equal sitemap_entry['url'], 'http://www.example.com/blog/this-is-a-blog-post'
144
+ assert_equal sitemap_entry['slug'], 'this-is-a-blog-post'
145
+ end
146
+ end
147
+
148
+
149
+
150
+ class BlogControllerTest < ActionController::TestCase
151
+ setup do
152
+ @routes = Engine.routes
153
+ end
154
+
155
+ test "should get blog home and it should have recent_posts defined" do
156
+ get "butter_home"
157
+ assert_response :success
158
+ assert_not_nil assigns(:recent_posts)
159
+ end
160
+
161
+ test "should get blog post and it should have post defined" do
162
+ get("butter_post", {'slug' => 'this-is-a-blog-post'})
163
+ assert_response :success
164
+ assert_not_nil assigns(:post)
165
+ end
166
+
167
+ test "should get author page" do
168
+ get("butter_author", {'author_slug' => 'api-test'})
169
+ assert_response :success
170
+ assert_not_nil assigns(:first_name)
171
+ assert_not_nil assigns(:last_name)
172
+ assert_not_nil assigns(:email)
173
+ assert_not_nil assigns(:recent_posts)
174
+ end
175
+
176
+ test "should get category page" do
177
+ get("butter_category", {'category_slug' => 'test-category'})
178
+ assert_response :success
179
+ assert_not_nil assigns(:name)
180
+ assert_not_nil assigns(:recent_posts)
181
+ end
182
+
183
+ test "sitemap should return xml" do
184
+ get("butter_sitemap", {'format' => 'xml'})
185
+ assert_select 'loc', "http://www.example.com/blog/this-is-a-blog-post"
186
+ end
187
+
188
+ test "atom feed should return xml" do
189
+ get("butter_feed", {'format' => 'atom'})
190
+ assert_select 'title', "This is a blog post"
191
+ end
192
+
193
+ test "rss feed should return xml" do
194
+ get("butter_feed", {'format' => 'rss'})
195
+ assert_select 'title', "This is a blog post"
196
+ end
197
+ end
198
+
199
+ # Ensure that the blog has access to the host application's helpers.
200
+ class ApplicationHelperTest < ActionView::TestCase
201
+ include ApplicationHelper
202
+
203
+ test "should return the blog title" do
204
+ assert_equal blog_title_helper, 'This is the Blog Title'
205
+ end
6
206
  end
7
- end
207
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.