tuning 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +1 -1
  4. data/lib/tuning/action_controller/base.rb +8 -6
  5. data/lib/tuning/action_view/base.rb +5 -5
  6. data/lib/tuning/version.rb +1 -1
  7. data/test/active_trail_test.rb +33 -0
  8. data/test/button_test.rb +17 -0
  9. data/test/content_tag_if_test.rb +17 -0
  10. data/test/dummy/app/controllers/status_controller.rb +27 -0
  11. data/test/dummy/app/views/layouts/application.html.erb +11 -11
  12. data/test/dummy/app/views/pages/index.html.erb +1 -0
  13. data/test/dummy/app/views/pages/other.html.erb +1 -0
  14. data/test/dummy/config/application.rb +1 -1
  15. data/test/dummy/config/initializers/secret_token.rb +1 -0
  16. data/test/dummy/config/locales/en.yml +11 -22
  17. data/test/dummy/config/routes.rb +6 -52
  18. data/test/dummy/log/test.log +4387 -84
  19. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  20. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  21. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  23. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  24. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  25. data/test/set_meta_test.rb +17 -0
  26. data/test/status_test.rb +55 -0
  27. data/test/test_helper.rb +3 -0
  28. metadata +47 -25
  29. data/test/dummy/db/development.sqlite3 +0 -0
  30. data/test/dummy/log/development.log +0 -14
  31. data/test/view_test.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2905dec322526dd21c3aeb41a722d1590fb9c4ba
4
- data.tar.gz: 04a821c58f34e36bb6dc3180c12310dff1b56c21
3
+ metadata.gz: 571eaac46fc919759e989e83b338d22237a18617
4
+ data.tar.gz: 229680a76b0acfb87afe35186a8b95eea44c286a
5
5
  SHA512:
6
- metadata.gz: f5b555d8d40cf9b7e4806a6edf7e7d6e843d6d3e9cee8ee77c5e7b77db9a1e2b85ba377e3204bcffc79daf32631dcf11355f1435f3614d195e2a34440ff594d1
7
- data.tar.gz: 39c78175744b75a3fb1700a5afb6ee63b6cedc0db9d4c1db13ada1cce970d71462a4d07f6d55265f719e149ce5a670c5a55b0c5288c6cc44c59fe2930f96c4a0
6
+ metadata.gz: 49039f3ab79c99fd630ad71bc116883eee558ee53c260230df92b0a4da7f8319bf3fb84175f676c50240edf7cfad9c8529480b7eefd9c7f68029b7519b1d08af
7
+ data.tar.gz: 26ff64770ec7e75bfc14bda0bb004c1f4761e9c6e9bc602d223866dca64ad3ebf77024d00442fccaefa295138b81bd2c6d097807da3cf798db262759d7a55cd5
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 Mattways
1
+ Copyright 2013 Museways
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- {<img src="https://codeclimate.com/github/mattways/tuning.png" />}[https://codeclimate.com/github/mattways/tuning] {<img src="https://travis-ci.org/mattways/tuning.png?branch=master" alt="Build Status" />}[https://travis-ci.org/mattways/tuning] {<img src="https://gemnasium.com/mattways/tuning.png" alt="Dependency Status" />}[https://gemnasium.com/mattways/tuning]
1
+ {<img src="https://badge.fury.io/rb/tuning.png" alt="Gem Version" />}[http://badge.fury.io/rb/tuning] {<img src="https://codeclimate.com/github/museways/tuning.png" />}[https://codeclimate.com/github/museways/tuning] {<img src="https://travis-ci.org/museways/tuning.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/tuning] {<img src="https://gemnasium.com/museways/tuning.png" alt="Dependency Status" />}[https://gemnasium.com/museways/tuning]
2
2
 
3
3
  = Tuning
4
4
 
@@ -8,10 +8,12 @@ module Tuning
8
8
  end
9
9
 
10
10
  protected
11
-
12
- def error(exception)
13
- logger.error exception.message
14
- exception.backtrace.each { |line| logger.error line }
11
+
12
+ def error(exception=nil)
13
+ if exception
14
+ logger.error exception.message
15
+ exception.backtrace.each { |line| logger.error line }
16
+ end
15
17
  respond_to do |format|
16
18
  format.json { head 500 }
17
19
  format.any { render file: Rails.root.join('public', '500.html'), status: 500, layout: false }
@@ -24,14 +26,14 @@ module Tuning
24
26
  format.any { render file: Rails.root.join('public', '404.html'), status: 404, layout: false }
25
27
  end
26
28
  end
27
-
29
+
28
30
  def unauthorized
29
31
  respond_to do |format|
30
32
  format.json { head 401 }
31
33
  format.any { render file: Rails.root.join('public', '422.html'), status: 401, layout: false }
32
34
  end
33
35
  end
34
-
36
+
35
37
  def forbidden
36
38
  respond_to do |format|
37
39
  format.json { head 403 }
@@ -13,15 +13,15 @@ module Tuning
13
13
  @meta_keywords = t('.meta.keywords', options)
14
14
  @meta_description = t('.meta.description', options)
15
15
  end
16
-
17
- def content_tag_if(condition, name, options=nil, &block)
18
- condition ? content_tag(name, options, &block) : capture(&block)
19
- end
20
-
16
+
21
17
  def active_trail?(path)
22
18
  (path == '/' && request.path == path) or request.path.start_with?(path)
23
19
  end
24
20
 
21
+ def content_tag_if(condition, name, options={}, &block)
22
+ condition ? content_tag(name, options, &block) : capture(&block)
23
+ end
24
+
25
25
  def submit_tag_with_button(value='Send', options={})
26
26
  button_tag({ type: 'submit', name: 'commit' }.update(options)) { content_tag(:span, value) }
27
27
  end
@@ -1,5 +1,5 @@
1
1
  module Tuning
2
2
 
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
 
5
5
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveTrailTest < ActionView::TestCase
4
+
5
+ test "should return true if path is in active trail" do
6
+ set_path '/some-path/other-path'
7
+ assert active_trail?('/')
8
+ assert active_trail?('/some-path')
9
+ end
10
+
11
+ test "should return true if path is the same as active trail" do
12
+ set_path '/'
13
+ assert active_trail?('/')
14
+
15
+ set_path '/some-path'
16
+ assert active_trail?('/some-path')
17
+ end
18
+
19
+ test "should return false if path is not in active trail" do
20
+ set_path '/'
21
+ assert !active_trail?('/some-path')
22
+
23
+ set_path '/some-path'
24
+ assert !active_trail?('/other-path')
25
+ end
26
+
27
+ private
28
+
29
+ def set_path(path)
30
+ self.request = OpenStruct.new(path: path)
31
+ end
32
+
33
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class ButtonTest < ActionView::TestCase
4
+
5
+ test "should use button with span inside instead of input" do
6
+ assert_equal '<button name="commit" type="submit"><span>Send</span></button>', submit_tag
7
+ end
8
+
9
+ test "should use the value as label" do
10
+ assert_equal '<button name="commit" type="submit"><span>Other</span></button>', submit_tag('Other')
11
+ end
12
+
13
+ test "should accept options as attributes" do
14
+ assert_equal '<button attribute="value" name="commit" type="submit"><span>Send</span></button>', submit_tag('Send', attribute: 'value')
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class ContentTagIfTest < ActionView::TestCase
4
+
5
+ test "should show tag if condition is true" do
6
+ assert_equal '<a>content</a>', content_tag_if(1 == 1, 'a') { 'content' }
7
+ end
8
+
9
+ test "should not show tag if condition if false" do
10
+ assert_equal 'content', content_tag_if(1 == 2, 'a') { 'content' }
11
+ end
12
+
13
+ test "should accept options as attributes" do
14
+ assert_equal '<a href="#">content</a>', content_tag_if(1 == 1, 'a', href: '#') { 'content' }
15
+ end
16
+
17
+ end
@@ -0,0 +1,27 @@
1
+ class StatusController < ApplicationController
2
+
3
+ def exception_action
4
+ raise 'error'
5
+ end
6
+
7
+ def error_action
8
+ error
9
+ end
10
+
11
+ def not_found_action
12
+ not_found
13
+ end
14
+
15
+ def unauthorized_action
16
+ unauthorized
17
+ end
18
+
19
+ def forbidden_action
20
+ forbidden
21
+ end
22
+
23
+ def unprocessable_entity_action
24
+ unprocessable_entity
25
+ end
26
+
27
+ end
@@ -1,14 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
- <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
3
+ <head>
4
+ <title><%= @meta_title %></title>
5
+ <meta name="description" content="<%= @meta_description %>" />
6
+ <meta name="keywords" content="<%= @meta_keywords %>" />
7
+ <%= csrf_meta_tags %>
8
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
9
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
10
+ </head>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
14
  </html>
@@ -0,0 +1 @@
1
+ <% set_meta %>
@@ -0,0 +1 @@
1
+ <% set_meta name: 'other' %>
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "tuning"
6
+ require 'tuning'
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -9,4 +9,5 @@
9
9
 
10
10
  # Make sure your secret_key_base is kept private
11
11
  # if you're sharing your code publicly.
12
+ Dummy::Application.config.secret_token = 'ebf2469bae653bb0ed9bc16c4485757036de73fd148942a3bf9940519149c443a572c3a9ab83386de40a0084743ab2db6a455f0218b553815c53ce04c697c300'
12
13
  Dummy::Application.config.secret_key_base = 'ebf2469bae653bb0ed9bc16c4485757036de73fd148942a3bf9940519149c443a572c3a9ab83386de40a0084743ab2db6a455f0218b553815c53ce04c697c300'
@@ -1,23 +1,12 @@
1
- # Files in the config/locales directory are used for internationalization
2
- # and are automatically loaded by Rails. If you want to use locales other
3
- # than English, add the necessary files in this directory.
4
- #
5
- # To use the locales, use `I18n.t`:
6
- #
7
- # I18n.t 'hello'
8
- #
9
- # In views, this is aliased to just `t`:
10
- #
11
- # <%= t('hello') %>
12
- #
13
- # To use a different locale, set it with `I18n.locale`:
14
- #
15
- # I18n.locale = :es
16
- #
17
- # This would use the information in config/locales/es.yml.
18
- #
19
- # To learn more, please read the Rails Internationalization guide
20
- # available at http://guides.rubyonrails.org/i18n.html.
21
-
22
1
  en:
23
- hello: "Hello world"
2
+ pages:
3
+ index:
4
+ meta:
5
+ title: 'index title'
6
+ description: 'index description'
7
+ keywords: 'index keywords'
8
+ other:
9
+ meta:
10
+ title: 'other %{name}'
11
+ description: 'other %{name}'
12
+ keywords: 'other %{name}'
@@ -1,56 +1,10 @@
1
1
  Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation: first created -> highest priority.
3
- # See how all your routes lay out with "rake routes".
4
-
5
- # You can have the root of your site routed with "root"
6
- # root 'welcome#index'
7
-
8
- # Example of regular route:
9
- # get 'products/:id' => 'catalog#view'
10
-
11
- # Example of named route that can be invoked with purchase_url(id: product.id)
12
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
-
14
- # Example resource route (maps HTTP verbs to controller actions automatically):
15
- # resources :products
16
-
17
- # Example resource route with options:
18
- # resources :products do
19
- # member do
20
- # get 'short'
21
- # post 'toggle'
22
- # end
23
- #
24
- # collection do
25
- # get 'sold'
26
- # end
27
- # end
28
-
29
- # Example resource route with sub-resources:
30
- # resources :products do
31
- # resources :comments, :sales
32
- # resource :seller
33
- # end
34
-
35
- # Example resource route with more complex sub-resources:
36
- # resources :products do
37
- # resources :comments
38
- # resources :sales do
39
- # get 'recent', on: :collection
40
- # end
41
- # end
42
2
 
43
- # Example resource route with concerns:
44
- # concern :toggleable do
45
- # post 'toggle'
46
- # end
47
- # resources :posts, concerns: :toggleable
48
- # resources :photos, concerns: :toggleable
3
+ get 'exception' => 'status#exception_action'
4
+ get 'error' => 'status#error_action'
5
+ get 'not_found' => 'status#not_found_action'
6
+ get 'unauthorized' => 'status#unauthorized_action'
7
+ get 'forbidden' => 'status#forbidden_action'
8
+ get 'unprocessable_entity' => 'status#unprocessable_entity_action'
49
9
 
50
- # Example resource route within a namespace:
51
- # namespace :admin do
52
- # # Directs /admin/products/* to Admin::ProductsController
53
- # # (app/controllers/admin/products_controller.rb)
54
- # resources :products
55
- # end
56
10
  end