ecrire 0.24.1 → 0.25.0

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Rakefile +2 -2
  4. data/lib/ecrire/app/controllers/admin/posts_controller.rb +2 -2
  5. data/lib/ecrire/app/controllers/application_controller.rb +19 -14
  6. data/lib/ecrire/app/controllers/ecrire/theme_controller.rb +11 -16
  7. data/lib/ecrire/app/helpers/application_helper.rb +0 -18
  8. data/lib/ecrire/app/models/post.rb +8 -8
  9. data/lib/ecrire/app/models/tag.rb +17 -0
  10. data/lib/ecrire/app/views/admin/posts/new.html.erb +1 -1
  11. data/lib/ecrire/application.rb +1 -1
  12. data/lib/ecrire/config/environment.rb +1 -1
  13. data/lib/ecrire/onboarding/controllers/databases_controller.rb +2 -1
  14. data/lib/ecrire/onboarding/controllers/onboarding_controller.rb +2 -1
  15. data/lib/ecrire/onboarding/controllers/users_controller.rb +1 -1
  16. data/lib/ecrire/onboarding/views/databases/index.html.erb +1 -1
  17. data/lib/ecrire/onboarding/views/layouts/application.html.erb +5 -1
  18. data/lib/ecrire/onboarding/views/onboarding/welcome.html.erb +1 -1
  19. data/lib/ecrire/onboarding/views/users/index.html.erb +1 -1
  20. data/lib/ecrire/theme/engine.rb +1 -0
  21. data/lib/ecrire/theme/template/controllers/posts_controller.rb +27 -0
  22. data/lib/ecrire/theme/template/routes.rb +2 -0
  23. data/lib/ecrire/theme/template/views/layouts/application.html.erb +6 -1
  24. data/lib/ecrire/theme/template/views/posts/_post.html.erb +2 -2
  25. data/lib/ecrire/theme/template/views/posts/index.html.erb +1 -1
  26. data/lib/ecrire/theme/template/views/static/customize/_layout.html.erb +5 -1
  27. data/lib/ecrire/version.rb +1 -1
  28. data/test/editor/controllers/posts_controller_test.rb +32 -0
  29. data/test/editor/controllers/tags_controller_test.rb +14 -0
  30. data/test/editor/theme/routes.rb +4 -0
  31. data/test/fixtures/titles.yml +3 -0
  32. data/test/onboarding/controllers/databases_controller_test.rb +24 -0
  33. data/test/onboarding/controllers/onboarding_controller_test.rb +31 -0
  34. data/test/onboarding/controllers/users_controller_test.rb +54 -0
  35. data/test/test_controller.rb +6 -1
  36. data/test/theme/controllers/posts_controller_test.rb +22 -0
  37. data/test/theme/theme/config.ru +3 -0
  38. data/test/theme/theme/controllers/posts_controller.rb +10 -0
  39. data/test/theme/theme/routes.rb +16 -0
  40. data/test/theme/theme/secrets.yml +8 -0
  41. data/test/theme/theme/views/posts/index.html.erb +14 -0
  42. data/test/theme/theme/views/posts/show.html.erb +8 -0
  43. metadata +18 -7
  44. /data/lib/ecrire/onboarding/assets/javascripts/{base.js → theme.js} +0 -0
  45. /data/lib/ecrire/onboarding/assets/stylesheets/{base.css.scss → theme.css.scss} +0 -0
  46. /data/lib/ecrire/theme/template/assets/javascripts/{base.js.coffee → theme.js.coffee} +0 -0
  47. /data/lib/ecrire/theme/template/assets/stylesheets/{base.css.scss → theme.css.scss} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b518f76df0cd5599696a1d33a2f8d623f5cdf91e
4
- data.tar.gz: e922c18cc01868164064b23cbbf626b5c146e03f
3
+ metadata.gz: 3fcb3e04a26a184a4a0c334415d276f85622427a
4
+ data.tar.gz: 4291e04867ed0c6e5f372a0f7271ae2a10557324
5
5
  SHA512:
6
- metadata.gz: d36e33aa48fc3bd3ae0310d977c0aed7b43f148bdf972416ab60d46b8acaf1338013f6b98075ecfe1c6a25e751208d0c06d1cb13c89265d72953ecc35240932d
7
- data.tar.gz: 5cf832bb2d0f70f03f785f8f825a544f989b9d342d7a08e1d973d631683cd0ea63ecdbe059fef032288e44b01410d9c164d3dcf6a6888e977348ab1e45cc72eb
6
+ metadata.gz: 922ddfce245632546f95b59e7866db2411f57018626aa205d9df87bd00a2c46279a23f4cecb501fd9ab1be62fea88c37cf3f9760a869a69e0ee4f3cb5c7f34a4
7
+ data.tar.gz: 5a5572199c40d7c95b40ee807ae914a9413992388d729b6395a5b9455b0e578666edcbef368b1446c1457322abf7a94e2b47728c6da891dd5e94d46245099d61
data/.gitignore CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  # Ignore all logfiles and tempfiles.
15
15
  log
16
- /tmp
16
+ tmp
17
17
 
18
18
  .DS_Store
19
19
  Gemfile.lock
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ namespace :database do
16
16
  end
17
17
 
18
18
  namespace :test do
19
- ['editor', 'onboarding'].each do |name|
19
+ ['editor', 'onboarding', 'theme'].each do |name|
20
20
  task = Ecrire::TestTask.new(name) do |t|
21
21
  t.theme = Dir.pwd + "/test/#{name}/theme"
22
22
  t.libs << "test"
@@ -28,7 +28,7 @@ namespace :test do
28
28
  end
29
29
 
30
30
  task :test do
31
- %w(test:editor test:onboarding).each do |name|
31
+ %w(test:editor test:onboarding test:theme).each do |name|
32
32
  Rake::Task[name].invoke
33
33
  end
34
34
  end
@@ -22,7 +22,7 @@ module Admin
22
22
  render 'new' and return
23
23
  end
24
24
 
25
- redirect_to edit_admin_post_path(@post)
25
+ redirect_to url('/admin/posts/:post.id/edit', post: @post)
26
26
  end
27
27
 
28
28
  def destroy
@@ -47,7 +47,7 @@ module Admin
47
47
  when 'publish'
48
48
  @post.publish!
49
49
  flash[:notice] = t(".successful", title: @post.title)
50
- redirect_to post_path(@post) and return
50
+ redirect_to url(Ecrire::Theme::Engine.post_path, post: @post) and return
51
51
  when 'unpublish'
52
52
  @post.unpublish!
53
53
  end
@@ -1,9 +1,8 @@
1
1
  class ApplicationController < ::ActionController::Base
2
-
3
2
  protect_from_forgery with: :exception
4
- helper_method :current_user, :signed_in?
5
3
 
6
- helper_method :warden, :post_path
4
+ helper_method :current_user, :signed_in?
5
+ helper_method :warden, :post_path, :url
7
6
 
8
7
  def current_user
9
8
  warden.user
@@ -13,17 +12,22 @@ class ApplicationController < ::ActionController::Base
13
12
  !warden.user.nil?
14
13
  end
15
14
 
16
- # This is the less ugly hack I could find. The reason why this is here
17
- # is because helpers are hard to debug due to their anonymous Module use.
18
- def post_path(post, options = {})
19
- options[:controller] = :posts
20
- options[:action] = :show
21
- options[:year] = post.published_at.year
22
- options[:month] = post.published_at.month
23
-
24
- options[:id] = (options.delete(:title) || post.titles.first).slug
25
-
26
- theme.url_for options
15
+ def url(path, options = {})
16
+ records = options.with_indifferent_access
17
+ regex = /(:([a-z]+)\.([a-z]+))/i
18
+ path.gsub! regex do |match|
19
+ records[$2].send($3)
20
+ end
21
+
22
+ if options.delete(:full_path)
23
+ options[:path] = path
24
+ options[:host] ||= request.host
25
+ options[:protocol] ||= request.protocol
26
+ options[:port] ||= request.port
27
+ ActionDispatch::Http::URL.full_url_for(options)
28
+ else
29
+ path
30
+ end
27
31
  end
28
32
 
29
33
 
@@ -36,4 +40,5 @@ class ApplicationController < ::ActionController::Base
36
40
  def warden
37
41
  env['warden']
38
42
  end
43
+
39
44
  end
@@ -1,11 +1,15 @@
1
1
  module Ecrire
2
2
  class ThemeController < ::ApplicationController
3
3
 
4
+ unless Rails.env.development?
5
+ rescue_from ActiveRecord::RecordNotFound, with: :redirect_home
6
+ rescue_from ActionController::RoutingError, with: :redirect_home
7
+ rescue_from ActionView::ActionViewError, with: :redirect_home
8
+ end
9
+
4
10
  before_action :pagination, only: :index
5
11
  protect_from_forgery except: :index
6
12
 
7
- helper_method :post, :posts
8
-
9
13
  def index
10
14
  respond_to do |format|
11
15
  format.html
@@ -17,27 +21,18 @@ module Ecrire
17
21
  end
18
22
 
19
23
  def show
20
- redirect_to :root and return if post.nil?
21
- redirect_to :root and return unless post.published?
22
- if post.titles.first != @title
23
- redirect_to post_path(post), status: :moved_permanently
24
- end
25
24
  end
26
25
 
27
26
  protected
28
27
 
29
- def posts
30
- @posts ||= Post.published.page(params[:page]).per(params[:per]).order('published_at DESC')
31
- end
32
-
33
- def post
34
- @title ||= Title.find_by_slug(params[:id])
35
- @post ||= @title.post
36
- end
37
-
38
28
  def pagination
39
29
  params[:per] ||= 10
40
30
  params[:page] ||= 1
41
31
  end
32
+
33
+ def redirect_home(exception)
34
+ flash[:errors] = t('errors.request.not_found')
35
+ redirect_to '/'
36
+ end
42
37
  end
43
38
  end
@@ -16,13 +16,6 @@ module ApplicationHelper
16
16
  end
17
17
  end
18
18
 
19
- def assets_tags
20
- [
21
- stylesheet_link_tag("application", "base", media: "all", "data-turbolinks-track" => true),
22
- javascript_include_tag("application", "base", "data-turbolinks-track" => true)
23
- ].join.html_safe
24
- end
25
-
26
19
  def meta_informations_tags
27
20
  [
28
21
  content_tag(:link, nil, rel: 'alternate', type: 'application/rss+xml', title: 'RSS', href: '/feed'),
@@ -50,15 +43,4 @@ module ApplicationHelper
50
43
  content_tag :body, html_options, &block
51
44
  end
52
45
 
53
-
54
- def flash_messages
55
- return if flash.empty?
56
-
57
- flash.map do |name, msg|
58
- content_tag :div, class: %W(flash #{name}) do
59
- content_tag(:span, h(msg), class: %w(message))
60
- end
61
- end.join.html_safe
62
- end
63
-
64
46
  end
@@ -38,6 +38,14 @@ class Post < ActiveRecord::Base
38
38
  (self.titles.first || self.titles.new).name
39
39
  end
40
40
 
41
+ def year
42
+ published_at.year
43
+ end
44
+
45
+ def month
46
+ published_at.month
47
+ end
48
+
41
49
  def slug
42
50
  self.titles.first.slug
43
51
  end
@@ -62,14 +70,6 @@ class Post < ActiveRecord::Base
62
70
  published_at.nil?
63
71
  end
64
72
 
65
- def to_param
66
- if self.instance_of?(Admin::Post)
67
- id.to_s
68
- else
69
- slug
70
- end
71
- end
72
-
73
73
  def content
74
74
  (self.compiled_content || super || '').html_safe
75
75
  end
@@ -2,4 +2,21 @@ class Tag < ActiveRecord::Base
2
2
  def ==(other)
3
3
  self.class.table_name == other.class.table_name && self.id == other.id
4
4
  end
5
+
6
+ def posts
7
+ post_scope = ->(tag) { where '? = ANY (posts.tags)', tag.id }
8
+ options = {}
9
+ reflection = ActiveRecord::Reflection::HasManyReflection.new(:posts, post_scope, options, self.class)
10
+ association = PostsAssociation.new(self, reflection)
11
+ @posts ||= ActiveRecord::Associations::CollectionProxy.new(Post, association)
12
+ end
13
+
14
+ private
15
+
16
+ class PostsAssociation < ActiveRecord::Associations::HasManyAssociation
17
+ def scope(opts = {})
18
+ Post.where('? = ANY (posts.tags)', owner.id).published.order('published_at DESC')
19
+ end
20
+ end
21
+
5
22
  end
@@ -11,7 +11,7 @@
11
11
  <% if @post.errors.any? %>
12
12
  <ul class='errors'>
13
13
  <% @post.errors.each do |key, message| %>
14
- <%= content_tag :li, message %>
14
+ <%= content_tag :li, message, key: key %>
15
15
  <% end %>
16
16
  </ul>
17
17
  <% else %>
@@ -26,7 +26,7 @@ module Ecrire
26
26
  @paths ||= begin
27
27
  paths = super
28
28
  paths.add 'config/routes.rb', with: 'routes.rb'
29
- paths.add 'config/locales', with: 'locales', glob: "*.{rb,yml}"
29
+ paths.add 'config/locales', with: 'locales', glob: "**/*.{rb,yml}"
30
30
  paths
31
31
  end
32
32
  end
@@ -18,7 +18,7 @@ Ecrire::Application.configure do
18
18
  lambda do |filename, path|
19
19
  path =~ /assets/ && !%w(.js .css).include?(File.extname(filename))
20
20
  end,
21
- /^(admin|application|base)\.(css|js)$/
21
+ /^(admin|application)\.(css|js)$/
22
22
  ]
23
23
 
24
24
  Warden::Manager.serialize_into_session do |user|
@@ -15,6 +15,7 @@ class DatabasesController < OnboardingController
15
15
  begin
16
16
  ActiveRecord::Base.configurations = {
17
17
  'development' => info,
18
+ 'test' => info,
18
19
  'production' => info
19
20
  }
20
21
  ActiveRecord::Base.establish_connection
@@ -26,7 +27,7 @@ class DatabasesController < OnboardingController
26
27
  render 'index' and return
27
28
  end
28
29
 
29
- redirect_to :users
30
+ redirect_to '/users'
30
31
  end
31
32
 
32
33
  protected
@@ -1,5 +1,4 @@
1
1
  class OnboardingController < ApplicationController
2
- include Ecrire::Onboarding::Engine.routes.url_helpers
3
2
 
4
3
  def index
5
4
  if File.exist?(Rails.application.paths['config/secrets'].expanded.last)
@@ -13,6 +12,8 @@ class OnboardingController < ApplicationController
13
12
  def save_configurations!
14
13
  File.open(Rails.application.paths['config/secrets'].expanded.last, 'w') do |file|
15
14
  config = ActiveRecord::Base.configurations
15
+ config['development'] ||= {}
16
+ config['production'] ||= {}
16
17
  config['development']['secret_key_base'] = config['production']['secret_key'] = Rails.application.secrets.secret_key_base
17
18
  file.write(config.to_yaml)
18
19
  end
@@ -10,7 +10,7 @@ class UsersController < OnboardingController
10
10
 
11
11
  if user.errors.blank?
12
12
  save_configurations!
13
- redirect_to :root
13
+ redirect_to '/'
14
14
  else
15
15
  render 'index'
16
16
  end
@@ -15,7 +15,7 @@
15
15
  </div>
16
16
 
17
17
 
18
- <%= form_tag databases_path, method: :post do %>
18
+ <%= form_tag '/databases', method: :post do %>
19
19
 
20
20
  <% unless @exception.nil? %>
21
21
  <div class='error' as='Message'>
@@ -3,7 +3,11 @@
3
3
 
4
4
  <head>
5
5
  <%= title_tag 'Before you start blogging...' %>
6
- <%= assets_tags %>
6
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
7
+ <%= javascript_include_tag "application", "base", "data-turbolinks-track" => true %>
8
+
9
+ <%= stylesheet_link_tag "theme", media: "all", "data-turbolinks-track" => true %>
10
+ <%= javascript_include_tag "theme", "base", "data-turbolinks-track" => true %>
7
11
  <%= meta_informations_tags %>
8
12
  </head>
9
13
 
@@ -7,6 +7,6 @@
7
7
 
8
8
 
9
9
  <section class='welcome'>
10
- <%= link_to 'Configure', databases_path, class: %w(button) %>
10
+ <%= link_to 'Configure', '/databases', class: %w(button) %>
11
11
  </section>
12
12
 
@@ -2,7 +2,7 @@
2
2
  <section>
3
3
  <h2>Create a user</h2>
4
4
 
5
- <%= form_for user, method: :post do |f| %>
5
+ <%= form_for user, method: :post, url: '/users' do |f| %>
6
6
  <% if user.errors.any? %>
7
7
  <%= content_tag :div, class: %w(error), as: 'Message' do %>
8
8
  <%= content_tag :p, user.errors.full_messages.first %>
@@ -1,6 +1,7 @@
1
1
  module Ecrire
2
2
  module Theme
3
3
  class Engine < Rails::Engine
4
+ attr_accessor :post_path
4
5
 
5
6
  initializer 'ecrire.logs', before: :initialize_logger do |app|
6
7
  unless Rails.env.test?
@@ -1,2 +1,29 @@
1
1
  class PostsController < Ecrire::ThemeController
2
+ helper_method :post, :posts
3
+
4
+ def index
5
+ @posts = posts.published.includes(:titles).order('published_at DESC').page(params[:page]).per(params[:per])
6
+ @tags = Tag.all
7
+ super
8
+ end
9
+
10
+ def show
11
+ redirect_to :root and return if post.nil?
12
+ redirect_to :root and return unless post.published?
13
+ if post.titles.first != @title
14
+ redirect_to theme.post_path(post.year, post.month, post), status: :moved_permanently
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def posts
21
+ @posts ||= Post.published.page(params[:page]).per(params[:per]).order('published_at DESC')
22
+ end
23
+
24
+ def post
25
+ @title ||= Title.find_by_slug(params[:id])
26
+ @post ||= @title.post
27
+ end
28
+
2
29
  end
@@ -1,3 +1,5 @@
1
+ Ecrire::Theme::Engine.post_path = '/:post.year/:post.month/:post.slug/'
2
+
1
3
  Ecrire::Theme::Engine.routes.draw do
2
4
  root 'posts#index'
3
5
 
@@ -3,7 +3,12 @@
3
3
 
4
4
  <head>
5
5
  <%= title_tag %>
6
- <%= assets_tags %>
6
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
7
+ <%= javascript_include_tag "application", "base", "data-turbolinks-track" => true %>
8
+
9
+ <%= stylesheet_link_tag "theme", media: "all", "data-turbolinks-track" => true %>
10
+ <%= javascript_include_tag "theme", "base", "data-turbolinks-track" => true %>
11
+
7
12
  <%= meta_informations_tags %>
8
13
  </head>
9
14
 
@@ -1,9 +1,9 @@
1
1
  <li class="post">
2
- <%= content_tag :h2, link_to(post.title, post_path(post)) %>
2
+ <%= content_tag :h2, link_to(post.title, url('/:post.year/:post.month/:post.slug', post: post)) %>
3
3
  <%= content_tag :time, l(post.published_at.to_date, format: :long) %>
4
4
  <div class='content'>
5
5
  <%= post.excerpt %>
6
6
  </div>
7
7
 
8
- <%= link_to 'Read more', post_path(post), class: %w(read) %>
8
+ <%= link_to 'Read more', url('/:post.year/:post.month/:post.slug/', post: post), class: %w(read) %>
9
9
  </li>
@@ -7,7 +7,7 @@
7
7
  <div class='posts empty'>
8
8
  <p>You haven't published yet.</p>
9
9
  <% if signed_in? %>
10
- <%= link_to 'Create a new post', new_title_admin_posts_path %>
10
+ <%= link_to 'Create a new post', url('/admin/posts/new') %>
11
11
  <% end %>
12
12
  </div>
13
13
  <% end %>
@@ -3,7 +3,11 @@
3
3
 
4
4
  <head>
5
5
  <%= '<'.html_safe %>%= title_tag %>
6
- <%= '<'.html_safe %>%= assets_tags %>
6
+ <%= '<'.html_safe %>%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
7
+ <%= '<'.html_safe %>%= javascript_include_tag "application", "base", "data-turbolinks-track" => true %>
8
+
9
+ <%= '<'.html_safe %>%= stylesheet_link_tag "theme", media: "all", "data-turbolinks-track" => true %>
10
+ <%= '<'.html_safe %>%= javascript_include_tag "theme", "base", "data-turbolinks-track" => true %>
7
11
  <%= '<'.html_safe %>%= meta_informations_tags %>
8
12
  </head>
9
13
 
@@ -1,3 +1,3 @@
1
1
  module Ecrire
2
- VERSION = '0.24.1'
2
+ VERSION = '0.25.0'
3
3
  end
@@ -0,0 +1,32 @@
1
+ require 'test_controller'
2
+ require 'editor/test_helper'
3
+
4
+ class PostsControllerTest < TestController
5
+ tests Admin::PostsController
6
+
7
+ test "cannot create a new post if the user isn't logged in" do
8
+ assert_throws :warden, "Expecting Warden to throw a symbol" do
9
+ post :create, post: {title: 'A new post'}
10
+ end
11
+ end
12
+
13
+ test 'creating a new post should redirect to the editor' do
14
+ log_in!
15
+ post :create, post: {title: 'A new post'}
16
+ assert_redirected_to @controller.url('/admin/posts/:post.id/edit', post: assigns(:post))
17
+ end
18
+
19
+ test 'a new post with an existing title should render errors' do
20
+ log_in!
21
+ post :create, post: {title: Post.first.title}
22
+ assert_select 'ul.errors' do
23
+ assert_select 'li[key=title]'
24
+ end
25
+ end
26
+
27
+ test "publishing a post redirect the user to the post's URL" do
28
+ log_in!
29
+ put :update, id: Post.status(:draft).first.id, button: :publish
30
+ assert_redirected_to @controller.url(Ecrire::Theme::Engine.post_path, post: assigns(:post))
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_controller'
2
+ require 'editor/test_helper'
3
+
4
+ class TagsControllerTest < TestController
5
+ tests Admin::Posts::TagsController
6
+
7
+ test 'can create a new tag' do
8
+ log_in!
9
+ post :create, post_id: Post.published.last, tag: {name: 'A new tag'}, format: :js
10
+ assert_response :success
11
+ end
12
+
13
+ end
14
+
@@ -1,5 +1,9 @@
1
+ Ecrire::Theme::Engine.post_path = '/:post.year/:post.month/:post.slug/'
2
+
1
3
  Ecrire::Theme::Engine.routes.draw do
4
+
2
5
  get '/:year/:month/:id', controller: :posts, action: :show, constraints: { year: /\d+/, month: /\d+/ }, as: "post"
6
+
3
7
  get '/feed', controller: :posts, action: :index, defaults: { format: :rss }
4
8
 
5
9
  resources :posts, only: [:index]
@@ -1,11 +1,14 @@
1
1
  published_history:
2
2
  name: "An old title"
3
+ slug: 'an-old-title'
3
4
  post: published
4
5
 
5
6
  published_current:
6
7
  name: "Current Title"
8
+ slug: 'current-title'
7
9
  post: published
8
10
 
9
11
  draft:
10
12
  name: "A draft"
13
+ slug: 'a-draft'
11
14
  post: draft
@@ -1,4 +1,28 @@
1
1
  require 'test_controller'
2
2
 
3
3
  class DatabasesControllerTest < TestController
4
+ tests DatabasesController
5
+
6
+ setup do
7
+ @routes = Ecrire::Onboarding::Engine.routes
8
+ end
9
+
10
+ test 'show error if the connection is refused' do
11
+ post :create, database: {user: 'invalid!', password: 'Nothing', name: 'ecrire_test'}
12
+ assert_response :success
13
+ assert_select 'div.error' do
14
+ assert_select 'p', 1
15
+ end
16
+ end
17
+
18
+ test 'even if the connection to the server is done, secrets.yml is not yet generated' do
19
+ post :create, database: {user: 'postgres', password: '', name: 'ecrire_test'}
20
+ assert Rails.application.paths['config/secrets'].existent.empty?
21
+ end
22
+
23
+ test 'redirect to users if the connection is successful' do
24
+ post :create, database: {user: 'postgres', password: '', name: 'ecrire_test'}
25
+ assert_redirected_to '/users'
26
+ end
27
+
4
28
  end
@@ -0,0 +1,31 @@
1
+ require 'test_controller'
2
+
3
+ class OnboadingControllerTest < TestController
4
+ tests OnboardingController
5
+
6
+ setup do
7
+ @routes = Ecrire::Onboarding::Engine.routes
8
+ end
9
+
10
+ test 'show welcome page when using access the root page' do
11
+ get :index
12
+ assert_response :success
13
+ assert_template :welcome
14
+ end
15
+
16
+
17
+ test 'show complete page if secrets.yml exists' do
18
+ File.open(Rails.application.paths['config/secrets'].expanded.last, 'w') do |file|
19
+ file.write('')
20
+ end
21
+
22
+ get :index
23
+ assert_response :success
24
+ assert_template :complete
25
+ end
26
+
27
+ teardown do
28
+ file = Rails.application.paths['config/secrets'].existent
29
+ FileUtils.rm(file) unless file.nil?
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_controller'
2
+
3
+ class UsersControllerTest < TestController
4
+ tests UsersController
5
+
6
+ # I'm hardcoding those values right now because I think
7
+ # it's easy for someone to set a new database. Maybe I could make these test depends on
8
+ # the databases controller so the setup would actually be a simple posts to that controller..
9
+ #
10
+ # On the flip side, that would make it look like an integration tests... anyway.
11
+ setup do
12
+ info ||= {
13
+ 'adapter' => 'postgresql',
14
+ 'database' => 'ecrire_test',
15
+ 'user' => 'postgres',
16
+ 'password' => 'password',
17
+ 'encoding' => 'utf8'
18
+ }
19
+ ActiveRecord::Base.configurations = { 'test' => info }
20
+ ActiveRecord::Base.establish_connection
21
+ migrate!
22
+ @routes = Ecrire::Onboarding::Engine.routes
23
+ end
24
+
25
+ def migrate!
26
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = ActiveRecord::Base.configurations
27
+ ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
28
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
29
+ ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
30
+ ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
31
+ end
32
+ end
33
+
34
+
35
+ test 'should show errors if there are problems with the user submitted' do
36
+ post :create, user: { email: 'bob@dilan.ca', password: 'password', password_confirmation: 'password1' }
37
+ assert_template :index
38
+ assert_select 'div.error' do
39
+ assert_select 'p', 1
40
+ end
41
+ end
42
+
43
+
44
+ test 'configuration should be saved as soon as the user is created' do
45
+ post :create, user: { email: 'bob@dilan.ca', password: 'password', password_confirmation: 'password' }
46
+ assert_redirected_to '/'
47
+ assert Rails.application.paths['config/secrets'].existent.any?
48
+ end
49
+
50
+ teardown do
51
+ file = Rails.application.paths['config/secrets'].existent
52
+ FileUtils.rm(file) unless file.nil?
53
+ end
54
+ end
@@ -3,11 +3,16 @@ require 'warden'
3
3
 
4
4
  class TestController < ActionController::TestCase
5
5
 
6
- def setup
6
+ setup do
7
7
  @routes = Rails.application.routes
8
8
  @controller.env['warden'] = @request.env['warden'] = Warden::Proxy.new(@request.env, self.class.manager)
9
9
  end
10
10
 
11
+ def log_in!(user = nil)
12
+ user ||= User.first
13
+ proxy.set_user user
14
+ end
15
+
11
16
  def self.manager
12
17
  @manager ||= Warden::Manager.new(self,
13
18
  {
@@ -0,0 +1,22 @@
1
+ require 'test_controller'
2
+ require 'test_helper'
3
+
4
+ class PostsControllerTest < TestController
5
+ tests PostsController
6
+
7
+ setup do
8
+ @routes = Ecrire::Theme::Engine.routes
9
+ end
10
+
11
+ test "redirect if page doesn't exist" do
12
+ get :show, year: 323, month: 1, id: "doesn't exist"
13
+ assert_redirected_to '/'
14
+ end
15
+
16
+ test 'show post if it exists' do
17
+ p = Post.published.first
18
+ get :show, year: p.year, month: p.month, id: p.slug
19
+ assert_response :success
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ require 'ecrire'
2
+
3
+ run Ecrire::Application.initialize!
@@ -0,0 +1,10 @@
1
+ class PostsController < Ecrire::ThemeController
2
+ def index
3
+ @posts = Post.published
4
+ end
5
+
6
+ def show
7
+ @title ||= Title.find_by_slug!(params[:id])
8
+ @post ||= @title.post
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ Ecrire::Theme::Engine.post_path = '/:post.year/:post.month/:post.slug/'
2
+
3
+ Ecrire::Theme::Engine.routes.draw do
4
+ root 'posts#index'
5
+
6
+ get '/:year/:month/:id', controller: :posts, action: :show, constraints: { year: /\d+/, month: /\d+/ }, as: "post"
7
+ get '/feed', controller: :posts, action: :index, defaults: { format: :rss }
8
+
9
+ resources :posts, only: [:index]
10
+
11
+ resources :tags
12
+
13
+ get '/:view', to: 'static#show'
14
+
15
+ end
16
+
@@ -0,0 +1,8 @@
1
+ test:
2
+ secret_key_base: 'kasjdklasj !*u3 12812u kjH JH!@ uh21ek jh12l12k'
3
+ adapter: postgresql
4
+ database: ecrire_test
5
+ user: postgres
6
+ encoding: utf8
7
+ s3:
8
+ bucket_name: 'test'
@@ -0,0 +1,14 @@
1
+ <% if @posts.any? %>
2
+ <ol class='posts'>
3
+ <%= render @posts %>
4
+ <%= paginate @posts %>
5
+ </ol>
6
+ <% else %>
7
+ <div class='posts empty'>
8
+ <p>You haven't published yet.</p>
9
+ <% if signed_in? %>
10
+ <%= link_to 'Create a new post', new_title_admin_posts_path %>
11
+ <% end %>
12
+ </div>
13
+ <% end %>
14
+
@@ -0,0 +1,8 @@
1
+ <%= content_tag :h2, @post.title %>
2
+ <%= content_tag :time, l(@post.published_at.to_date, format: :long) %>
3
+
4
+ <div class="content">
5
+ <%= @post.content.html_safe %>
6
+ </div>
7
+
8
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecrire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pier-Olivier Thibault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Blog engine on Rails
14
14
  email: pothibo@gmail.com
@@ -196,15 +196,15 @@ files:
196
196
  - lib/ecrire/onboarding/assets/images/github-logo.png
197
197
  - lib/ecrire/onboarding/assets/images/profile.png
198
198
  - lib/ecrire/onboarding/assets/images/twitter-logo.png
199
- - lib/ecrire/onboarding/assets/javascripts/base.js
200
199
  - lib/ecrire/onboarding/assets/javascripts/databases/information.js.coffee
201
200
  - lib/ecrire/onboarding/assets/javascripts/message.js.coffee
202
- - lib/ecrire/onboarding/assets/stylesheets/base.css.scss
201
+ - lib/ecrire/onboarding/assets/javascripts/theme.js
203
202
  - lib/ecrire/onboarding/assets/stylesheets/complete.css.scss
204
203
  - lib/ecrire/onboarding/assets/stylesheets/fonts.css.scss
205
204
  - lib/ecrire/onboarding/assets/stylesheets/form.css.scss
206
205
  - lib/ecrire/onboarding/assets/stylesheets/message.css.scss
207
206
  - lib/ecrire/onboarding/assets/stylesheets/terminal.css.scss
207
+ - lib/ecrire/onboarding/assets/stylesheets/theme.css.scss
208
208
  - lib/ecrire/onboarding/assets/stylesheets/variables.css.scss
209
209
  - lib/ecrire/onboarding/assets/stylesheets/welcome.css.scss
210
210
  - lib/ecrire/onboarding/controllers/databases_controller.rb
@@ -225,12 +225,12 @@ files:
225
225
  - lib/ecrire/theme/template/Procfile
226
226
  - lib/ecrire/theme/template/Rakefile
227
227
  - lib/ecrire/theme/template/assets/images/.keep
228
- - lib/ecrire/theme/template/assets/javascripts/base.js.coffee
229
- - lib/ecrire/theme/template/assets/stylesheets/base.css.scss
228
+ - lib/ecrire/theme/template/assets/javascripts/theme.js.coffee
230
229
  - lib/ecrire/theme/template/assets/stylesheets/code.css.scss
231
230
  - lib/ecrire/theme/template/assets/stylesheets/footer.css.scss
232
231
  - lib/ecrire/theme/template/assets/stylesheets/header.css.scss
233
232
  - lib/ecrire/theme/template/assets/stylesheets/home.css.scss
233
+ - lib/ecrire/theme/template/assets/stylesheets/theme.css.scss
234
234
  - lib/ecrire/theme/template/config.ru
235
235
  - lib/ecrire/theme/template/controllers/posts_controller.rb
236
236
  - lib/ecrire/theme/template/helpers/blog_helper.rb
@@ -249,7 +249,9 @@ files:
249
249
  - lib/ecrire/theme/template/views/static/customize/_layout.html.erb
250
250
  - lib/ecrire/theme/template/views/static/customize/_post.html
251
251
  - lib/ecrire/version.rb
252
+ - test/editor/controllers/posts_controller_test.rb
252
253
  - test/editor/controllers/sessions_controller_test.rb
254
+ - test/editor/controllers/tags_controller_test.rb
253
255
  - test/editor/helpers/base_helper_test.rb
254
256
  - test/editor/models/image_test.rb
255
257
  - test/editor/models/post_test.rb
@@ -273,10 +275,19 @@ files:
273
275
  - test/fixtures/users.yml
274
276
  - test/initializations/engine_test.rb
275
277
  - test/onboarding/controllers/databases_controller_test.rb
278
+ - test/onboarding/controllers/onboarding_controller_test.rb
279
+ - test/onboarding/controllers/users_controller_test.rb
276
280
  - test/onboarding/theme/.keep
277
281
  - test/test_controller.rb
278
282
  - test/test_helper.rb
279
283
  - test/test_task.rb
284
+ - test/theme/controllers/posts_controller_test.rb
285
+ - test/theme/theme/config.ru
286
+ - test/theme/theme/controllers/posts_controller.rb
287
+ - test/theme/theme/routes.rb
288
+ - test/theme/theme/secrets.yml
289
+ - test/theme/theme/views/posts/index.html.erb
290
+ - test/theme/theme/views/posts/show.html.erb
280
291
  homepage: http://pothibo.com
281
292
  licenses:
282
293
  - MIT
@@ -297,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
308
  version: '0'
298
309
  requirements: []
299
310
  rubyforge_project:
300
- rubygems_version: 2.2.2
311
+ rubygems_version: 2.0.14
301
312
  signing_key:
302
313
  specification_version: 4
303
314
  summary: Blog engine