redis_dictionary 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +37 -0
  3. data/Rakefile +41 -0
  4. data/app/assets/javascripts/redis_dictionary/application.js +16 -0
  5. data/app/assets/javascripts/redis_dictionary/bootstrap.js +10 -0
  6. data/app/assets/javascripts/redis_dictionary/jquery.autosize.js +192 -0
  7. data/app/assets/javascripts/redis_dictionary/translations.js +35 -0
  8. data/app/assets/stylesheets/redis_dictionary/application.css +13 -0
  9. data/app/assets/stylesheets/redis_dictionary/bootstrap_and_overrides.css +7 -0
  10. data/app/assets/stylesheets/redis_dictionary/translations.css +42 -0
  11. data/app/controllers/redis_dictionary/application_controller.rb +25 -0
  12. data/app/controllers/redis_dictionary/translations_controller.rb +51 -0
  13. data/app/helpers/redis_dictionary/application_helper.rb +39 -0
  14. data/app/models/redis_dictionary/translation.rb +64 -0
  15. data/app/views/layouts/redis_dictionary/application.html.erb +43 -0
  16. data/app/views/redis_dictionary/translations/_key_translation.html.erb +22 -0
  17. data/app/views/redis_dictionary/translations/create.js.erb +14 -0
  18. data/app/views/redis_dictionary/translations/destroy.js.erb +2 -0
  19. data/app/views/redis_dictionary/translations/index.html.erb +69 -0
  20. data/config/environment.rb +1 -0
  21. data/config/initializers/will_paginate.rb +1 -0
  22. data/config/routes.rb +14 -0
  23. data/lib/redis_dictionary.rb +25 -0
  24. data/lib/redis_dictionary/configuration.rb +21 -0
  25. data/lib/redis_dictionary/engine.rb +53 -0
  26. data/lib/redis_dictionary/version.rb +3 -0
  27. data/test/dummy/README.rdoc +261 -0
  28. data/test/dummy/Rakefile +7 -0
  29. data/test/dummy/app/assets/images/favicon.ico +0 -0
  30. data/test/dummy/app/assets/javascripts/application.js +15 -0
  31. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  32. data/test/dummy/app/controllers/application_controller.rb +4 -0
  33. data/test/dummy/app/helpers/application_helper.rb +3 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +59 -0
  37. data/test/dummy/config/boot.rb +10 -0
  38. data/test/dummy/config/database.yml +25 -0
  39. data/test/dummy/config/environment.rb +6 -0
  40. data/test/dummy/config/environments/development.rb +33 -0
  41. data/test/dummy/config/environments/production.rb +70 -0
  42. data/test/dummy/config/environments/test.rb +37 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
  44. data/test/dummy/config/initializers/inflections.rb +16 -0
  45. data/test/dummy/config/initializers/mime_types.rb +6 -0
  46. data/test/dummy/config/initializers/secret_token.rb +9 -0
  47. data/test/dummy/config/initializers/session_store.rb +9 -0
  48. data/test/dummy/config/initializers/wrap_parameters.rb +15 -0
  49. data/test/dummy/config/locales/en.yml +5 -0
  50. data/test/dummy/config/routes.rb +4 -0
  51. data/test/dummy/db/schema.rb +16 -0
  52. data/test/dummy/db/test.sqlite3 +0 -0
  53. data/test/dummy/log/test.log +1003 -0
  54. data/test/dummy/public/404.html +26 -0
  55. data/test/dummy/public/422.html +26 -0
  56. data/test/dummy/public/500.html +25 -0
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/dummy/script/rails +7 -0
  59. data/test/functional/redis_dictionary/translations_controller_test.rb +37 -0
  60. data/test/integration/redis_dictionary/translations_test.rb +113 -0
  61. data/test/redis_dictionary/configuration_test.rb +24 -0
  62. data/test/redis_dictionary_test.rb +22 -0
  63. data/test/test_helper.rb +43 -0
  64. data/test/unit/helpers/redis_dictionary/application_helper_test.rb +61 -0
  65. data/test/unit/redis_dictionary/translation_test.rb +89 -0
  66. metadata +360 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ #!/usr/bin/env ruby
3
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
+
5
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
6
+ require File.expand_path('../../config/boot', __FILE__)
7
+ require 'rails/commands'
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ module RedisDictionary
5
+ class TranslationsControllerTest < ActionController::TestCase
6
+
7
+ # produced error
8
+ # test "should get index" do
9
+ # get :index, use_route: :redis_dictionary
10
+ # assert_response :success
11
+ # assert_not_nil assigns(:translations)
12
+ # end
13
+
14
+ test "should post create as HTML" do
15
+ post :create, key: 'test.lol', value: 'lol', locale: 'es', use_route: :redis_dictionary, format: :html
16
+ assert_redirected_to redis_dictionary_root_path
17
+ end
18
+
19
+ test "should post create as JS" do
20
+ post :create, key: 'test.lol', value: 'lol', locale: 'es', use_route: :redis_dictionary, format: :js
21
+ assert_not_nil assigns(:digest)
22
+ assert_response :success
23
+ end
24
+
25
+ test "should delete destroy as HTML" do
26
+ delete :destroy, use_route: :redis_dictionary, format: :html
27
+ assert_redirected_to redis_dictionary_root_path
28
+
29
+ end
30
+
31
+ test "should delete destroy as JS" do
32
+ delete :destroy, use_route: :redis_dictionary, format: :js
33
+ assert_response :success
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'digest/md5'
4
+
5
+ class TranslationsTest < ActionDispatch::IntegrationTest
6
+
7
+ setup do
8
+ Capybara.current_driver = Capybara.javascript_driver
9
+ end
10
+
11
+ # failed no message given :(
12
+ # test "load translations" do
13
+ # visit '/'
14
+ # within("h1") do
15
+ # assert page.has_content? 'Translations'
16
+ # end
17
+
18
+ # end
19
+
20
+
21
+ # produced error 'click_link'
22
+ # test "create a translation" do
23
+ # visit '/'
24
+ # click_link 'add-translation-link'
25
+ # find("#add-translation").visible?
26
+
27
+ # within('#form-translation') do
28
+ # fill_in 'locale', with: 'en'
29
+ # fill_in 'key', with: 'test.dog'
30
+ # fill_in 'value', with: 'dog'
31
+ # click_button 'Submit'
32
+ # end
33
+
34
+ # digest = digest_key('test.dog')
35
+
36
+ # assert_no_selector("#add-translation")
37
+ # assert page.has_css?("#translation_key_#{digest}")
38
+ # within("#translation_key_#{digest}") do
39
+ # assert page.has_content? 'test.dog'
40
+ # assert page.has_content? 'dog'
41
+ # end
42
+
43
+ # RedisDictionary::Translation.destroy(digest)
44
+ # end
45
+
46
+ #throws error
47
+ # test "edit a translation" do
48
+ # digest = RedisDictionary::Translation.create('test.dog', 'dog', 'en')
49
+
50
+ # visit '/'
51
+
52
+ # within("#translation_key_#{digest}") do
53
+ # click_link 'en.test.dog'
54
+ # end
55
+
56
+ # find("#add-translation").visible?
57
+ # within('#form-translation') do
58
+ # assert page.has_field? 'locale', with: 'en'
59
+ # assert page.has_field? 'key', with: 'test.dog'
60
+ # assert page.has_field? 'value', with: 'dog'
61
+
62
+ # fill_in 'value', with: 'the dog'
63
+ # click_button 'Submit'
64
+ # end
65
+
66
+ # assert_no_selector("#add-translation")
67
+ # assert page.has_css?("#translation_key_#{digest}")
68
+ # within("#translation_key_#{digest}") do
69
+ # assert page.has_content? 'test.dog'
70
+ # assert page.has_content? 'the dog'
71
+ # end
72
+
73
+ # RedisDictionary::Translation.destroy(digest)
74
+ # end
75
+
76
+ # fails for now :(
77
+ # test "destroy a translation" do
78
+ # digest = RedisDictionary::Translation.create('test.dog', 'dog', 'en')
79
+ # assert page.has_css?("#translation_key_#{digest}")
80
+ # click_link "destroy-#{digest}"
81
+ # RedisDictionary::Translation.destroy(digest)
82
+ # end
83
+
84
+ # test "search keys" do
85
+ # RedisDictionary::Translation.create('test.dog', 'dog', 'en')
86
+ # RedisDictionary::Translation.create('test.house', 'house', 'en')
87
+ # RedisDictionary::Translation.create('test.chair', 'chair', 'en')
88
+ # visit '/'
89
+
90
+ # within('#search-form') do
91
+ # fill_in 'query', with: 'o'
92
+ # click_button 'search'
93
+ # assert page.has_field? 'query', with: 'o'
94
+ # end
95
+
96
+ # within("#translation_key_#{digest_key('test.dog')}") do
97
+ # assert page.has_content? 'test.dog'
98
+ # assert page.has_content? 'dog'
99
+ # end
100
+
101
+ # within("#translation_key_#{digest_key('test.house')}") do
102
+ # assert page.has_content? 'test.house'
103
+ # assert page.has_content? 'house'
104
+ # end
105
+
106
+ # assert_no_selector("#translation_key_#{digest_key('test.chair')}")
107
+ # end
108
+
109
+
110
+ def digest_key(key)
111
+ Digest::MD5.hexdigest(key)
112
+ end
113
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ module RedisDictionary
5
+
6
+ class ConfigurationTest < ActiveSupport::TestCase
7
+
8
+ def setup
9
+ @i18n_configuration = RedisDictionary::Configuration.new
10
+ end
11
+
12
+ test "should set :authentication_method to nil" do
13
+ assert_nil @i18n_configuration.authentication_method
14
+ end
15
+
16
+ test "should set :layout to nil" do
17
+ assert_nil @i18n_configuration.layout
18
+ end
19
+
20
+ test "should set :inline_main_app_named_routes to false" do
21
+ assert !@i18n_configuration.inline_main_app_named_routes
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class RedisDictionaryTest < ActiveSupport::TestCase
5
+
6
+ test "should allow developers to set configurations with a block" do
7
+ initial_value = RedisDictionary.configuration.layout
8
+ RedisDictionary.configure do |config|
9
+ config.layout = "custom_layout_developer"
10
+ end
11
+ user_set_value = RedisDictionary.configuration.inline_main_app_named_routes
12
+ assert_not_equal initial_value, user_set_value
13
+ end
14
+
15
+ def teardown
16
+ RedisDictionary.configure do |config|
17
+ config.inspect
18
+ end
19
+ end
20
+
21
+ end
22
+ §
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start do
11
+ add_filter "/test/"
12
+ add_filter "/config/"
13
+ end
14
+
15
+
16
+ # Configure Rails Environment
17
+ ENV["RAILS_ENV"] = "test"
18
+
19
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
20
+ require "rails/test_help"
21
+
22
+ require 'capybara/rails'
23
+ require 'capybara/poltergeist'
24
+ Capybara.javascript_driver = :poltergeist
25
+
26
+ Rails.backtrace_cleaner.remove_silencers!
27
+
28
+ # Load support files
29
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
30
+
31
+ # Load fixtures from the engine
32
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
33
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
34
+ end
35
+
36
+ class ActionController::TestCase
37
+ include RedisDictionary::Engine.routes.url_helpers
38
+ end
39
+
40
+ class ActionDispatch::IntegrationTest
41
+ # Make the Capybara DSL available in all integration tests
42
+ include Capybara::DSL
43
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ module RedisDictionary
5
+ class ApplicationHelperTest < ActionView::TestCase
6
+
7
+
8
+ class MainAppApplicationHelperBench
9
+ def dummy_thing_path
10
+ "/dummy_thing"
11
+ end
12
+ def dummy_thing_url
13
+ "http://host/dummy_thing"
14
+ end
15
+ def secret
16
+ end
17
+ end
18
+
19
+ class RedisDictionaryApplicationHelperBench
20
+ include RedisDictionary::ApplicationHelper
21
+
22
+ def main_app
23
+ MainAppApplicationHelperBench.new
24
+ end
25
+ end
26
+
27
+
28
+ def raw_helper
29
+ RedisDictionaryApplicationHelperBench.new
30
+ end
31
+
32
+ test "should not know named routes of the main app if not configured" do
33
+ RedisDictionary.configure {|c| c.inline_main_app_named_routes = false }
34
+ assert_raise(NoMethodError){
35
+ raw_helper.dummy_thing_path
36
+ }
37
+
38
+ assert_raise(NoMethodError){
39
+ raw_helper.dummy_thing_url
40
+ }
41
+ end
42
+
43
+ test "should know named routes of the main app" do
44
+ RedisDictionary.configure {|c| c.inline_main_app_named_routes = true }
45
+ assert_equal "/dummy_thing", raw_helper.dummy_thing_path
46
+ assert_equal "http://host/dummy_thing", raw_helper.dummy_thing_url
47
+ end
48
+
49
+ test "should not know anything but named routes of the main app" do
50
+ RedisDictionary.configure {|c| c.inline_main_app_named_routes = true }
51
+ assert_raise(NoMethodError) { raw_helper.secret }
52
+ end
53
+
54
+ test "should not know other routes" do
55
+ RedisDictionary.configure {|c| c.inline_main_app_named_routes = true }
56
+ assert_raise(NoMethodError) { raw_helper.junk_path }
57
+ assert_raise(NoMethodError) { raw_helper.junk_url }
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ module RedisDictionary
5
+ class TranslationTest < ActiveSupport::TestCase
6
+
7
+ def setup
8
+ Engine.redis.flushdb
9
+ I18n.reload!
10
+ Engine.redis.sadd('keys', 'a')
11
+ Engine.redis.sadd('keys', 'b')
12
+ Engine.redis.sadd('system_keys', 'b')
13
+ Engine.redis.sadd('system_keys', 'c')
14
+ end
15
+
16
+ def create_test_translation
17
+ Translation.create('test.hello', 'Hola', 'es')
18
+ end
19
+
20
+ test "should create a key_digest" do
21
+ digest = create_test_translation
22
+
23
+ Translation.destroy(digest)
24
+ assert !Engine.redis.exists('es.test.hello')
25
+ end
26
+
27
+ test "should return union of keys and system_keys sorted" do
28
+ assert_equal ['a', 'b', 'c'], Translation.all
29
+ end
30
+
31
+ test "should return match keys" do
32
+ Engine.redis.sadd('keys', 'test.horse.hear')
33
+ Engine.redis.sadd('system_keys', 'test.horse.nose')
34
+
35
+ assert_equal ['test.horse.hear', 'test.horse.nose'], Translation.all('horse')
36
+ assert_equal ['test.horse.nose'], Translation.all('nose')
37
+ end
38
+
39
+ test "should return sorted array of keys" do
40
+ assert_equal ['a', 'b'], Translation.keys
41
+ end
42
+
43
+ test "should return sorted array of system_keys" do
44
+ assert_equal ['b', 'c'], Translation.system_keys
45
+ end
46
+
47
+
48
+ test "should be true if exists in system_keys" do
49
+ assert !Translation.system_key?('a')
50
+ assert Translation.system_key?('b')
51
+ assert Translation.system_key?('c')
52
+ end
53
+
54
+ test "should add the key to the set keys" do
55
+ create_test_translation
56
+ assert Translation.keys.include?('test.hello')
57
+ end
58
+
59
+ test "should be exist on I18n translations" do
60
+ create_test_translation
61
+ assert_equal 'Hola', I18n.t('test.hello', locale: 'es')
62
+ end
63
+
64
+ test "should be true if the translation exists" do
65
+ create_test_translation
66
+
67
+ assert Translation.exists?('test.hello', 'es')
68
+ assert !Translation.exists?('test.hello', 'en')
69
+ end
70
+
71
+ test "should remove the key from keys" do
72
+ digest = create_test_translation
73
+ Translation.destroy(digest)
74
+ assert !Translation.keys.include?('test.hello')
75
+ end
76
+
77
+ test "should remove from keys_digest" do
78
+ digest = create_test_translation
79
+ Translation.destroy(digest)
80
+ assert !Engine.redis.hexists('keys_digest', digest)
81
+ end
82
+
83
+ test "should remove the translation" do
84
+ digest = create_test_translation
85
+ Translation.destroy(digest)
86
+ assert !Engine.redis.exists('es.test.hello')
87
+ end
88
+ end
89
+ end