locale_setter 0.3.0 → 0.4.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +19 -1
  5. data/README.md +44 -27
  6. data/Rakefile +67 -4
  7. data/lib/locale_setter.rb +28 -1
  8. data/lib/locale_setter/configuration.rb +8 -0
  9. data/lib/locale_setter/{rails.rb → controller.rb} +6 -6
  10. data/lib/locale_setter/domain.rb +17 -0
  11. data/lib/locale_setter/generic.rb +11 -5
  12. data/lib/locale_setter/railtie.rb +17 -0
  13. data/lib/locale_setter/user.rb +15 -6
  14. data/lib/locale_setter/version.rb +1 -1
  15. data/locale_setter.gemspec +1 -0
  16. data/spec/dummy/.rspec +2 -0
  17. data/spec/dummy/Rakefile +7 -0
  18. data/spec/dummy/app/controllers/application_controller.rb +16 -0
  19. data/spec/dummy/app/controllers/articles_controller.rb +9 -0
  20. data/spec/dummy/app/controllers/users_controller.rb +9 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  22. data/spec/dummy/app/models/article.rb +2 -0
  23. data/spec/dummy/app/models/user.rb +2 -0
  24. data/spec/dummy/app/views/_form.html.erb +25 -0
  25. data/spec/dummy/app/views/articles/_form.html.erb +25 -0
  26. data/spec/dummy/app/views/articles/edit.html.erb +6 -0
  27. data/spec/dummy/app/views/articles/index.html.erb +7 -0
  28. data/spec/dummy/app/views/articles/new.html.erb +5 -0
  29. data/spec/dummy/app/views/articles/show.html.erb +15 -0
  30. data/spec/dummy/app/views/edit.html.erb +6 -0
  31. data/spec/dummy/app/views/index.html.erb +25 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +11 -0
  33. data/spec/dummy/app/views/new.html.erb +5 -0
  34. data/spec/dummy/app/views/show.html.erb +15 -0
  35. data/spec/dummy/bin/rails +4 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/config/application.rb +68 -0
  38. data/spec/dummy/config/boot.rb +5 -0
  39. data/spec/dummy/config/database.yml +25 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +33 -0
  42. data/spec/dummy/config/environments/production.rb +57 -0
  43. data/spec/dummy/config/environments/test.rb +31 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  45. data/spec/dummy/config/initializers/inflections.rb +15 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  47. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  48. data/spec/dummy/config/initializers/session_store.rb +8 -0
  49. data/spec/dummy/config/locales/arr.yml +2 -0
  50. data/spec/dummy/config/locales/en.yml +2 -0
  51. data/spec/dummy/config/locales/http.yml +2 -0
  52. data/spec/dummy/config/locales/user.yml +2 -0
  53. data/spec/dummy/config/mongoid.yml +80 -0
  54. data/spec/dummy/config/routes.rb +4 -0
  55. data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
  56. data/spec/dummy/db/schema.rb +30 -0
  57. data/spec/dummy/db/seeds.rb +1 -0
  58. data/spec/dummy/lib/tasks/test.rake +16 -0
  59. data/spec/dummy/public/404.html +26 -0
  60. data/spec/dummy/public/422.html +26 -0
  61. data/spec/dummy/public/500.html +25 -0
  62. data/spec/dummy/public/favicon.ico +0 -0
  63. data/spec/dummy/script/rails +6 -0
  64. data/spec/{locale/rails_spec.rb → locale_setter/controller_spec.rb} +6 -6
  65. data/spec/locale_setter/domain_spec.rb +19 -0
  66. data/spec/{locale → locale_setter}/generic_spec.rb +16 -7
  67. data/spec/{locale → locale_setter}/http_spec.rb +0 -0
  68. data/spec/locale_setter/locale_setter_spec.rb +28 -0
  69. data/spec/{locale → locale_setter}/matcher_spec.rb +0 -0
  70. data/spec/{locale → locale_setter}/user_spec.rb +0 -0
  71. data/spec/request_helper.rb +8 -0
  72. data/spec/requests/request_spec.rb +43 -0
  73. data/spec/support/dummy_app.rb +85 -0
  74. data/spec/support/matchers/have_text.rb +50 -0
  75. metadata +142 -13
@@ -1,3 +1,3 @@
1
1
  module LocaleSetter
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency "rake", "~>10.0.3"
21
21
  gem.add_development_dependency "rspec", "~>2.13.0"
22
+ gem.add_development_dependency 'capybara'
22
23
  end
data/spec/dummy/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,16 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ before_filter :set_user
5
+
6
+ def current_user
7
+ @current_user
8
+ end
9
+ helper_method :current_user
10
+
11
+ def set_user
12
+ if params[:user]
13
+ @current_user = ::User.first
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class ArticlesController < ApplicationController
2
+ def index
3
+ @articles = Article.all
4
+ end
5
+
6
+ def show
7
+ @article = Article.find(params[:id])
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class UsersController < ApplicationController
2
+ def index
3
+ @users = User.all
4
+ end
5
+
6
+ def show
7
+ @user = User.find(params[:id])
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def hello_world
3
+ "Hello, world!"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ class Article < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@user) do |f| %>
2
+ <% if @user.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @user.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %><br />
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :locale %><br />
20
+ <%= f.text_field :locale %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <%= form_for(@article) do |f| %>
2
+ <% if @article.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @article.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br />
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :body %><br />
20
+ <%= f.text_area :body %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @article %> |
6
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,7 @@
1
+ <h1><%= t 'title' %></h1>
2
+
3
+ <h2>Params</h2>
4
+ <%= debug params %>
5
+
6
+ <h2>Current User</h2>
7
+ <%= debug current_user %>
@@ -0,0 +1,5 @@
1
+ <h1>New article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Title:</b>
5
+ <%= @article.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Body:</b>
10
+ <%= @article.body %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_article_path(@article) %> |
15
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing user</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @user %> |
6
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing users</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Locale</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @users.each do |user| %>
13
+ <tr>
14
+ <td><%= user.name %></td>
15
+ <td><%= user.locale %></td>
16
+ <td><%= link_to 'Show', user %></td>
17
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
18
+ <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New User', new_user_path %>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>SampleLocaleSetter</title>
5
+ </head>
6
+ <body>
7
+
8
+ <%= yield %>
9
+
10
+ </body>
11
+ </html>
@@ -0,0 +1,5 @@
1
+ <h1>New user</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @user.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Locale:</b>
10
+ <%= @user.locale %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_user_path(@user) %> |
15
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,68 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ def attempt_require(file)
4
+ require file
5
+ rescue LoadError
6
+ end
7
+
8
+ require 'rails/all'
9
+ require 'locale_setter'
10
+
11
+ module Dummy
12
+ class Application < Rails::Application
13
+ # Settings in config/environments/* take precedence over those specified here.
14
+ # Application configuration should go into files in config/initializers
15
+ # -- all .rb files in that directory are automatically loaded.
16
+
17
+ # Custom directories with classes and modules you want to be autoloadable.
18
+ # config.autoload_paths += %W(#{config.root}/extras)
19
+
20
+ # Only load the plugins named here, in the order given (default is alphabetical).
21
+ # :all can be used as a placeholder for all plugins not explicitly named.
22
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
23
+
24
+ # Activate observers that should always be running.
25
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
26
+
27
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
28
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
29
+ # config.time_zone = 'Central Time (US & Canada)'
30
+
31
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
32
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
33
+ # config.i18n.default_locale = :de
34
+
35
+ # Configure the default encoding used in templates for Ruby 1.9.
36
+ config.encoding = "utf-8"
37
+
38
+ # Configure sensitive parameters which will be filtered from the log file.
39
+ config.filter_parameters += [:password]
40
+
41
+ # Enable escaping HTML in JSON.
42
+ config.active_support.escape_html_entities_in_json = true
43
+
44
+ # Use SQL instead of Active Record's schema dumper when creating the database.
45
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
46
+ # like if you have constraints or database-specific column types
47
+ # config.active_record.schema_format = :sql
48
+
49
+ # Enforce whitelist mode for mass assignment.
50
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
51
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
52
+ # parameters by using an attr_accessible or attr_protected declaration.
53
+ config.active_record.whitelist_attributes = false
54
+
55
+ # Enable the asset pipeline
56
+ # config.assets.enabled = true
57
+
58
+ # Version of your assets, change this if you want to expire all your assets
59
+ # config.assets.version = '1.0'
60
+
61
+ # Tell Action Mailer not to deliver emails to the real world.
62
+ # The :test delivery method accumulates sent emails in the
63
+ # ActionMailer::Base.deliveries array.
64
+ config.action_mailer.delivery_method = :test
65
+ end
66
+ end
67
+
68
+ ActiveRecord::Migration.verbose = false
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
4
+
5
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,33 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Show full error reports and disable caching
10
+ config.consider_all_requests_local = true
11
+ config.action_controller.perform_caching = false
12
+
13
+ # Print deprecation notices to the Rails logger
14
+ config.active_support.deprecation = :log
15
+
16
+ # Only use best-standards-support built into browsers
17
+ config.action_dispatch.best_standards_support = :builtin
18
+
19
+ config.eager_load = false
20
+
21
+ # Raise exception on mass assignment protection for Active Record models
22
+ # config.active_record.mass_assignment_sanitizer = :strict
23
+
24
+ # Log the query plan for queries taking more than this (works
25
+ # with SQLite, MySQL, and PostgreSQL)
26
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
27
+
28
+ # Do not compress assets
29
+ # config.assets.compress = false
30
+
31
+ # Expands the lines which load the assets
32
+ # config.assets.debug = true
33
+ end
@@ -0,0 +1,57 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ config.eager_load = true
15
+
16
+ # Defaults to nil and saved in location specified by config.assets.prefix
17
+ # config.assets.manifest = YOUR_PATH
18
+
19
+ # Specifies the header that your server uses for sending files
20
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
21
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
22
+
23
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
24
+ # config.force_ssl = true
25
+
26
+ # See everything in the log (default is :info)
27
+ # config.log_level = :debug
28
+
29
+ # Prepend all log lines with the following tags
30
+ # config.log_tags = [ :subdomain, :uuid ]
31
+
32
+ # Use a different logger for distributed setups
33
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
34
+
35
+ # Use a different cache store in production
36
+ # config.cache_store = :mem_cache_store
37
+
38
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
39
+ # config.action_controller.asset_host = "http://assets.example.com"
40
+
41
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
42
+ # config.assets.precompile += %w( search.js )
43
+
44
+ # Enable threaded mode
45
+ # config.threadsafe!
46
+
47
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
48
+ # the I18n.default_locale when a translation can not be found)
49
+ config.i18n.fallbacks = true
50
+
51
+ # Send deprecation notices to registered listeners
52
+ config.active_support.deprecation = :notify
53
+
54
+ # Log the query plan for queries taking more than this (works
55
+ # with SQLite, MySQL, and PostgreSQL)
56
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
57
+ end