locale_setter 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +19 -0
- data/Gemfile +19 -1
- data/README.md +44 -27
- data/Rakefile +67 -4
- data/lib/locale_setter.rb +28 -1
- data/lib/locale_setter/configuration.rb +8 -0
- data/lib/locale_setter/{rails.rb → controller.rb} +6 -6
- data/lib/locale_setter/domain.rb +17 -0
- data/lib/locale_setter/generic.rb +11 -5
- data/lib/locale_setter/railtie.rb +17 -0
- data/lib/locale_setter/user.rb +15 -6
- data/lib/locale_setter/version.rb +1 -1
- data/locale_setter.gemspec +1 -0
- data/spec/dummy/.rspec +2 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +16 -0
- data/spec/dummy/app/controllers/articles_controller.rb +9 -0
- data/spec/dummy/app/controllers/users_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/models/article.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/_form.html.erb +25 -0
- data/spec/dummy/app/views/articles/_form.html.erb +25 -0
- data/spec/dummy/app/views/articles/edit.html.erb +6 -0
- data/spec/dummy/app/views/articles/index.html.erb +7 -0
- data/spec/dummy/app/views/articles/new.html.erb +5 -0
- data/spec/dummy/app/views/articles/show.html.erb +15 -0
- data/spec/dummy/app/views/edit.html.erb +6 -0
- data/spec/dummy/app/views/index.html.erb +25 -0
- data/spec/dummy/app/views/layouts/application.html.erb +11 -0
- data/spec/dummy/app/views/new.html.erb +5 -0
- data/spec/dummy/app/views/show.html.erb +15 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +68 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +33 -0
- data/spec/dummy/config/environments/production.rb +57 -0
- data/spec/dummy/config/environments/test.rb +31 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/arr.yml +2 -0
- data/spec/dummy/config/locales/en.yml +2 -0
- data/spec/dummy/config/locales/http.yml +2 -0
- data/spec/dummy/config/locales/user.yml +2 -0
- data/spec/dummy/config/mongoid.yml +80 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
- data/spec/dummy/db/schema.rb +30 -0
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/dummy/lib/tasks/test.rake +16 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/{locale/rails_spec.rb → locale_setter/controller_spec.rb} +6 -6
- data/spec/locale_setter/domain_spec.rb +19 -0
- data/spec/{locale → locale_setter}/generic_spec.rb +16 -7
- data/spec/{locale → locale_setter}/http_spec.rb +0 -0
- data/spec/locale_setter/locale_setter_spec.rb +28 -0
- data/spec/{locale → locale_setter}/matcher_spec.rb +0 -0
- data/spec/{locale → locale_setter}/user_spec.rb +0 -0
- data/spec/request_helper.rb +8 -0
- data/spec/requests/request_spec.rb +43 -0
- data/spec/support/dummy_app.rb +85 -0
- data/spec/support/matchers/have_text.rb +50 -0
- metadata +142 -13
data/locale_setter.gemspec
CHANGED
data/spec/dummy/.rspec
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -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,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,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,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,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,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
|