translation_center 1.7.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -2
- data/Rakefile +8 -13
- data/app/assets/javascripts/translation_center/application.js +1 -1
- data/app/assets/stylesheets/translation_center/application.css +1 -1
- data/app/assets/stylesheets/translation_center/translation_keys.css +3 -1
- data/app/controllers/translation_center/application_controller.rb +2 -2
- data/app/controllers/translation_center/translation_keys_controller.rb +4 -4
- data/app/models/translation_center/activity_query.rb +2 -3
- data/app/models/translation_center/category.rb +7 -2
- data/app/models/translation_center/translation.rb +54 -32
- data/app/models/translation_center/translation_key.rb +29 -18
- data/app/views/layouts/translation_center/application.html.haml +0 -2
- data/app/views/translation_center/translation_keys/_translation_keys.html.haml +3 -1
- data/app/views/translation_center/translations/_show.html.haml +3 -3
- data/config/routes.rb +3 -3
- data/db/development.sqlite3 +0 -0
- data/{test/dummy/db/migrate/20130410082611_devise_create_users.rb → db/migrate/20130410082600_devise_create_users.rb} +0 -0
- data/{test/dummy/db/migrate/20130410082701_create_articles.rb → db/migrate/20130410082601_create_articles.rb} +0 -0
- data/{test/dummy/db/migrate/20130410084711234392_create_translation_center_categories.rb → db/migrate/20130410084602_create_translation_center_categories.rb} +0 -0
- data/{test/dummy/db/migrate/20130410084711235054_create_translation_center_translation_keys.rb → db/migrate/20130410084603_create_translation_center_translation_keys.rb} +0 -0
- data/{test/dummy/db/migrate/20130410084711235601_create_translation_center_translations.rb → db/migrate/20130410084604_create_translation_center_translations.rb} +0 -0
- data/{test/dummy/db/migrate/20130410084711_acts_as_votable_migration.rb → db/migrate/20130410084605_acts_as_votable_migration.rb} +1 -0
- data/{test/dummy/db/migrate/20130410084711235602_install_audited.rb → db/migrate/20130410084606_install_audited.rb} +0 -0
- data/{test/dummy/db/migrate/20130410113111070575_add_de_status_translation_center_translation_keys.rb → db/migrate/20130410113607_add_de_status_translation_center_translation_keys.rb} +0 -0
- data/{test/dummy/db/migrate/20130417134539377014_add_ar_status_translation_center_translation_keys.rb → db/migrate/20130417134608_add_ar_status_translation_center_translation_keys.rb} +0 -0
- data/{test/dummy/db/migrate/20130506103956_fix_translation_user_relation.rb → db/migrate/20130506103609_fix_translation_user_relation.rb} +0 -0
- data/{test/dummy/db/migrate/20130801102022_add_indicies.rb → db/migrate/20130801102610_add_indicies.rb} +0 -0
- data/{test/dummy/db → db}/schema.rb +13 -13
- data/{test/dummy/public/favicon.ico → db/test.sqlite3} +0 -0
- data/lib/generators/translation_center/add_lang/add_lang_generator.rb +5 -2
- data/lib/generators/translation_center/install/install_generator.rb +4 -4
- data/lib/translation_center/acts_as_translator.rb +1 -1
- data/lib/translation_center/engine.rb +7 -0
- data/lib/translation_center/translation_helpers.rb +1 -1
- data/lib/translation_center/translations_transfer.rb +6 -5
- data/lib/translation_center/version.rb +1 -1
- data/spec/controllers/categories_controller_spec.rb +47 -0
- data/spec/controllers/center_controller_spec.rb +77 -0
- data/spec/controllers/translation_keys_controller_spec.rb +87 -0
- data/spec/controllers/translations_controller_spec.rb +70 -0
- data/{test → spec}/dummy/README.rdoc +0 -0
- data/{test → spec}/dummy/Rakefile +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -1
- data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -1
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- data/{test → spec}/dummy/app/models/user.rb +2 -5
- data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -1
- data/{test → spec}/dummy/config.ru +0 -0
- data/{test → spec}/dummy/config/application.rb +10 -5
- data/{test → spec}/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +25 -0
- data/{test → spec}/dummy/config/environment.rb +2 -0
- data/{test → spec}/dummy/config/environments/development.rb +0 -0
- data/{test → spec}/dummy/config/environments/production.rb +0 -0
- data/{test → spec}/dummy/config/environments/test.rb +2 -2
- data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/{test → spec}/dummy/config/initializers/devise.rb +3 -1
- data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- data/{test → spec}/dummy/config/initializers/secret_token.rb +1 -1
- data/{test → spec}/dummy/config/initializers/session_store.rb +1 -1
- data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/{test → spec}/dummy/config/locales/devise.en.yml +0 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/{test → spec}/dummy/config/translation_center.yml +23 -6
- data/spec/dummy/db/migrate/20130410082611_devise_create_users.translation_center.rb +46 -0
- data/spec/dummy/db/migrate/20130410082701_create_articles.translation_center.rb +10 -0
- data/spec/dummy/db/migrate/20130410084702_create_translation_center_categories.translation_center.rb +9 -0
- data/spec/dummy/db/migrate/20130410084703_create_translation_center_translation_keys.translation_center.rb +14 -0
- data/spec/dummy/db/migrate/20130410084704_create_translation_center_translations.translation_center.rb +13 -0
- data/spec/dummy/db/migrate/20130410084711_acts_as_votable_migration.translation_center.rb +24 -0
- data/spec/dummy/db/migrate/20130410084712_install_audited.translation_center.rb +28 -0
- data/spec/dummy/db/migrate/20130410113113_add_de_status_translation_center_translation_keys.translation_center.rb +5 -0
- data/spec/dummy/db/migrate/20130417134534_add_ar_status_translation_center_translation_keys.rb +5 -0
- data/spec/dummy/db/migrate/20130506103956_fix_translation_user_relation.translation_center.rb +12 -0
- data/spec/dummy/db/migrate/20130801102021_add_indicies.translation_center.rb +8 -0
- data/spec/dummy/db/schema.rb +111 -0
- data/{test → spec}/dummy/public/404.html +0 -0
- data/{test → spec}/dummy/public/422.html +0 -0
- data/{test → spec}/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/{test → spec}/dummy/script/rails +0 -0
- data/spec/factories/category_factory.rb +5 -0
- data/spec/factories/translation_factory.rb +8 -0
- data/spec/factories/translation_key_factory.rb +5 -0
- data/spec/factories/user_factory.rb +6 -0
- data/spec/factories/vote_factory.rb +13 -0
- data/spec/lib/generators/translation_center/add_lang/add_lang_generator_spec.rb +26 -0
- data/spec/models/translation_center/category_spec.rb +39 -0
- data/spec/models/translation_center/translation_key_spec.rb +145 -0
- data/spec/models/translation_center/translation_spec.rb +117 -0
- data/spec/schema.rb +112 -0
- data/spec/spec_helper.rb +52 -0
- data/spec/support/devise.rb +3 -0
- metadata +360 -208
- data/test/dummy/app/assets/images/translation_center_logo.png +0 -0
- data/test/dummy/app/assets/javascripts/articles.js +0 -2
- data/test/dummy/app/assets/stylesheets/articles.css +0 -4
- data/test/dummy/app/assets/stylesheets/scaffold.css +0 -56
- data/test/dummy/app/controllers/application_controller.rb +0 -6
- data/test/dummy/app/controllers/articles_controller.rb +0 -85
- data/test/dummy/app/helpers/articles_helper.rb +0 -2
- data/test/dummy/app/models/article.rb +0 -7
- data/test/dummy/app/views/articles/_form.html.haml +0 -16
- data/test/dummy/app/views/articles/edit.html.haml +0 -7
- data/test/dummy/app/views/articles/index.html.haml +0 -32
- data/test/dummy/app/views/articles/new.html.haml +0 -5
- data/test/dummy/app/views/articles/show.html.haml +0 -14
- data/test/dummy/config/database.yml +0 -42
- data/test/dummy/config/locales/ar.yml +0 -6
- data/test/dummy/config/locales/de.yml +0 -2
- data/test/dummy/config/locales/en.yml +0 -361
- data/test/dummy/config/routes.rb +0 -10
- data/test/dummy/spec/spec_helper.rb +0 -38
- data/test/dummy/test/fixtures/articles.yml +0 -9
- data/test/dummy/test/fixtures/posts.yml +0 -9
- data/test/dummy/test/fixtures/users.yml +0 -11
- data/test/dummy/test/functional/articles_controller_test.rb +0 -49
- data/test/dummy/test/functional/posts_controller_test.rb +0 -49
- data/test/dummy/test/unit/article_test.rb +0 -7
- data/test/dummy/test/unit/helpers/articles_helper_test.rb +0 -4
- data/test/dummy/test/unit/helpers/posts_helper_test.rb +0 -4
- data/test/dummy/test/unit/post_test.rb +0 -7
- data/test/dummy/test/unit/user_test.rb +0 -7
- data/test/fixtures/translation_center/categories.yml +0 -7
- data/test/fixtures/translation_center/translation_keys.yml +0 -11
- data/test/fixtures/translation_center/translations.yml +0 -15
- data/test/functional/translation_center/categories_controller_test.rb +0 -51
- data/test/functional/translation_center/center_controller_test.rb +0 -9
- data/test/functional/translation_center/translation_keys_controller_test.rb +0 -51
- data/test/functional/translation_center/translations_controller_test.rb +0 -51
- data/test/integration/navigation_test.rb +0 -10
- data/test/test_helper.rb +0 -15
- data/test/translation_center_test.rb +0 -7
- data/test/unit/helpers/translation_center/categories_helper_test.rb +0 -6
- data/test/unit/helpers/translation_center/center_helper_test.rb +0 -6
- data/test/unit/helpers/translation_center/translation_keys_helper_test.rb +0 -6
- data/test/unit/helpers/translation_center/translations_helper_test.rb +0 -6
- data/test/unit/translation_center/category_test.rb +0 -9
- data/test/unit/translation_center/translation_key_test.rb +0 -9
- data/test/unit/translation_center/translation_test.rb +0 -9
@@ -4,7 +4,7 @@
|
|
4
4
|
- else
|
5
5
|
.tabbable.tabs-left.all_listing
|
6
6
|
|
7
|
-
%ul.nav.nav-tabs.translation_keys_listing
|
7
|
+
%ul.nav.nav-tabs.translation_keys_listing#keys_ul
|
8
8
|
- translation_keys.each_with_index do |translation_key, index|
|
9
9
|
= render 'translation_center/translation_keys/show_keys', translation_key: translation_key, index: index
|
10
10
|
|
@@ -14,3 +14,5 @@
|
|
14
14
|
= render 'translation_center/translation_keys/show', translation_key: translation_key, index: index
|
15
15
|
|
16
16
|
|
17
|
+
:javascript
|
18
|
+
$("#keys_ul").css('max-height', $(window).height()-220);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
.well.well-small.translation_box{ id: "translation_id_#{translation.id}", 'data-key-id' => translation.translation_key.id }
|
2
|
-
|
2
|
+
|
3
3
|
%div{class: "translation_info #{language_direction(to_lang)}"}
|
4
4
|
%span
|
5
5
|
= translation.value
|
6
|
-
|
6
|
+
|
7
7
|
- if translation_admin?
|
8
8
|
= link_to '×', translation_path(translation), method: :delete, data: { confirm: t('translation_center.actions.are_you_sure', :default => 'Are you sure?') }, class: 'close', remote: true
|
9
9
|
%br
|
@@ -22,7 +22,7 @@
|
|
22
22
|
= render 'translation_center/translations/accept_translation', translation: translation
|
23
23
|
.votes_count.badge.badge-success.pull-right
|
24
24
|
%span.count{ 'data-translation-id' => translation.id }
|
25
|
-
= translation.
|
25
|
+
= translation.votes_for.count
|
26
26
|
= t('.votings')
|
27
27
|
%a.pull-right{href: '#'}
|
28
28
|
- voted = current_user.voted_on?(translation)
|
data/config/routes.rb
CHANGED
@@ -11,7 +11,7 @@ TranslationCenter::Engine.routes.draw do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
resources :translation_keys, except: :create do
|
14
|
-
post :update_translation
|
14
|
+
post :update_translation, defaults: { format: 'json' }
|
15
15
|
get :translations
|
16
16
|
collection do
|
17
17
|
get :search
|
@@ -29,6 +29,6 @@ TranslationCenter::Engine.routes.draw do
|
|
29
29
|
root to: 'categories#index'
|
30
30
|
|
31
31
|
# set the language from and to for the user
|
32
|
-
|
33
|
-
|
32
|
+
get "/set_language_from" => 'center#set_language_from', as: :set_lang_from
|
33
|
+
get "/set_language_to" => 'center#set_language_to', as: :set_lang_to
|
34
34
|
end
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -11,13 +11,13 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20130801102021) do
|
15
15
|
|
16
16
|
create_table "articles", :force => true do |t|
|
17
17
|
t.string "title"
|
18
18
|
t.text "content"
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
19
|
+
t.datetime "created_at", :null => false
|
20
|
+
t.datetime "updated_at", :null => false
|
21
21
|
end
|
22
22
|
|
23
23
|
create_table "audits", :force => true do |t|
|
@@ -43,8 +43,8 @@ ActiveRecord::Schema.define(:version => 20130417134539377014) do
|
|
43
43
|
|
44
44
|
create_table "translation_center_categories", :force => true do |t|
|
45
45
|
t.string "name"
|
46
|
-
t.datetime "created_at"
|
47
|
-
t.datetime "updated_at"
|
46
|
+
t.datetime "created_at", :null => false
|
47
|
+
t.datetime "updated_at", :null => false
|
48
48
|
end
|
49
49
|
|
50
50
|
create_table "translation_center_translation_keys", :force => true do |t|
|
@@ -52,8 +52,8 @@ ActiveRecord::Schema.define(:version => 20130417134539377014) do
|
|
52
52
|
t.integer "category_id"
|
53
53
|
t.datetime "last_accessed"
|
54
54
|
t.string "en_status", :default => "untranslated"
|
55
|
-
t.datetime "created_at"
|
56
|
-
t.datetime "updated_at"
|
55
|
+
t.datetime "created_at", :null => false
|
56
|
+
t.datetime "updated_at", :null => false
|
57
57
|
t.string "de_status", :default => "untranslated"
|
58
58
|
t.string "ar_status", :default => "untranslated"
|
59
59
|
end
|
@@ -66,8 +66,8 @@ ActiveRecord::Schema.define(:version => 20130417134539377014) do
|
|
66
66
|
t.string "lang"
|
67
67
|
t.integer "translator_id"
|
68
68
|
t.string "status", :default => "pending"
|
69
|
-
t.datetime "created_at"
|
70
|
-
t.datetime "updated_at"
|
69
|
+
t.datetime "created_at", :null => false
|
70
|
+
t.datetime "updated_at", :null => false
|
71
71
|
t.string "translator_type"
|
72
72
|
end
|
73
73
|
|
@@ -84,8 +84,8 @@ ActiveRecord::Schema.define(:version => 20130417134539377014) do
|
|
84
84
|
t.datetime "last_sign_in_at"
|
85
85
|
t.string "current_sign_in_ip"
|
86
86
|
t.string "last_sign_in_ip"
|
87
|
-
t.datetime "created_at"
|
88
|
-
t.datetime "updated_at"
|
87
|
+
t.datetime "created_at", :null => false
|
88
|
+
t.datetime "updated_at", :null => false
|
89
89
|
end
|
90
90
|
|
91
91
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
@@ -98,8 +98,8 @@ ActiveRecord::Schema.define(:version => 20130417134539377014) do
|
|
98
98
|
t.string "voter_type"
|
99
99
|
t.boolean "vote_flag"
|
100
100
|
t.string "vote_scope"
|
101
|
-
t.datetime "created_at"
|
102
|
-
t.datetime "updated_at"
|
101
|
+
t.datetime "created_at", :null => false
|
102
|
+
t.datetime "updated_at", :null => false
|
103
103
|
end
|
104
104
|
|
105
105
|
add_index "votes", ["votable_id", "votable_type", "vote_scope"], :name => "index_votes_on_votable_id_and_votable_type_and_vote_scope"
|
File without changes
|
@@ -18,13 +18,16 @@ module TranslationCenter
|
|
18
18
|
langs.each do |lang|
|
19
19
|
@lang = lang
|
20
20
|
# check if language already supported
|
21
|
-
|
21
|
+
language_supported = TranslationCenter::TranslationKey.column_names.include?("#{lang.downcase.gsub("-","_")}_status")
|
22
|
+
if language_supported
|
22
23
|
puts 'This language is already supported, just make sure it is listed in config/translation_center.yml'
|
23
24
|
return
|
24
25
|
end
|
25
26
|
# Generate migration templates for the models needed
|
26
|
-
migration_template 'migrations/add_lang_status_translation_keys.rb',
|
27
|
+
migration_template 'migrations/add_lang_status_translation_keys.rb',
|
28
|
+
"db/migrate/add_#{lang.downcase.gsub("-","_")}_status_translation_center_translation_keys.rb"
|
27
29
|
end
|
30
|
+
|
28
31
|
puts "Language(s) added, don't forget to add the language(s) to config/translation_center.yml"
|
29
32
|
end
|
30
33
|
end
|
@@ -16,9 +16,9 @@ module TranslationCenter
|
|
16
16
|
migration_template 'migrations/create_translation_center_translations.rb', 'db/migrate/create_translation_center_translations.rb'
|
17
17
|
|
18
18
|
# generate votes if it doesn't already exist
|
19
|
-
unless ActiveRecord::Base.connection.table_exists? 'votes'
|
19
|
+
# unless ActiveRecord::Base.connection.table_exists? 'votes'
|
20
20
|
Rails::Generators.invoke('acts_as_votable:migration')
|
21
|
-
end
|
21
|
+
# end
|
22
22
|
|
23
23
|
copy_file 'config/translation_center.yml', 'config/translation_center.yml'
|
24
24
|
|
@@ -27,10 +27,10 @@ module TranslationCenter
|
|
27
27
|
|
28
28
|
sleep(1) # to avoid duplicate migrations between acts_as_votable and auditable
|
29
29
|
|
30
|
-
unless ActiveRecord::Base.connection.table_exists? 'audits'
|
30
|
+
# unless ActiveRecord::Base.connection.table_exists? 'audits'
|
31
31
|
# we use audited for tracking activity
|
32
32
|
Rails::Generators.invoke('audited:install')
|
33
|
-
end
|
33
|
+
# end
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -9,7 +9,7 @@ module ActsAsTranslator
|
|
9
9
|
module InstanceMethods
|
10
10
|
# returns the translation a user has made for a certain key in a certain language
|
11
11
|
def translation_for(key, lang)
|
12
|
-
self.translations.
|
12
|
+
self.translations.find_or_initialize_by(translation_key_id: key.id, lang: lang.to_s, translator_type: self.class.name)
|
13
13
|
end
|
14
14
|
|
15
15
|
# returns true if the user can admin translations
|
@@ -11,5 +11,12 @@ module TranslationCenter
|
|
11
11
|
|
12
12
|
class Engine < ::Rails::Engine
|
13
13
|
isolate_namespace TranslationCenter
|
14
|
+
|
15
|
+
config.generators do |g|
|
16
|
+
g.test_framework :rspec, :fixture => false
|
17
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
18
|
+
g.assets false
|
19
|
+
g.helper false
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
@@ -60,7 +60,7 @@ module TranslationCenter
|
|
60
60
|
complete_key = prepare_key(key, options) # prepare complete key
|
61
61
|
|
62
62
|
# add the new key or update it
|
63
|
-
translation_key = TranslationCenter::TranslationKey.
|
63
|
+
translation_key = TranslationCenter::TranslationKey.find_or_create_by(name: complete_key)
|
64
64
|
# UNCOMMENT THIS LATER TO SET LAST ACCESSED AT
|
65
65
|
# translation_key.update_attribute(:last_accessed, Time.now)
|
66
66
|
|
@@ -28,14 +28,17 @@ module TranslationCenter
|
|
28
28
|
# returns true if the translation was fonud in yaml
|
29
29
|
def self.yaml2db_key(locale, translation_key, translator, all_yamls)
|
30
30
|
I18n.locale = locale
|
31
|
-
translation = TranslationCenter::Translation.
|
31
|
+
translation = TranslationCenter::Translation.find_or_initialize_by(translation_key_id: translation_key.id, lang: locale.to_s, translator_id: translator.id)
|
32
32
|
translation.translator_type = TranslationCenter::CONFIG['translator_type']
|
33
33
|
|
34
34
|
# get the translation for this key from the yamls
|
35
35
|
value = get_translation_from_hash(translation_key.name, all_yamls[locale])
|
36
36
|
|
37
37
|
# if the value is not empty and is different from the existing value the update
|
38
|
-
if
|
38
|
+
if value.is_a? Proc
|
39
|
+
puts "proc removed for key #{translation_key.name}"
|
40
|
+
translation.destroy unless translation.new_record?
|
41
|
+
elsif !value.blank? && value != translation.value
|
39
42
|
translation.update_attribute(:value, value)
|
40
43
|
# accept this yaml translation
|
41
44
|
translation.accept if TranslationCenter::CONFIG['yaml2db_translations_accepted']
|
@@ -55,8 +58,7 @@ module TranslationCenter
|
|
55
58
|
# for each key create it in the db if it doesn't exist, and add its translation to
|
56
59
|
# the db in every locale
|
57
60
|
keys.each do |key|
|
58
|
-
|
59
|
-
translation_key = TranslationCenter::TranslationKey.find_or_initialize_by_name(key)
|
61
|
+
translation_key = TranslationCenter::TranslationKey.find_or_initialize_by(name: key)
|
60
62
|
if translation_key.new_record?
|
61
63
|
translation_key.save
|
62
64
|
new_keys += 1
|
@@ -97,7 +99,6 @@ module TranslationCenter
|
|
97
99
|
all_keys = all_yamls.collect do |check_locale, translations|
|
98
100
|
collect_keys([], translations).sort
|
99
101
|
end.flatten.uniq
|
100
|
-
|
101
102
|
puts "#{all_keys.size} #{all_keys.size == 1 ? 'unique key' : 'unique keys'} found."
|
102
103
|
|
103
104
|
locales = locale.blank? ? I18n.available_locales : [locale.to_sym]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module TranslationCenter
|
3
|
+
describe CategoriesController, :type => :controller do
|
4
|
+
let(:user) {FactoryGirl.create(:user)}
|
5
|
+
before(:each) do
|
6
|
+
sign_in user
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "GET index" do
|
10
|
+
it "assigns @categories & render index template" do
|
11
|
+
categories = Category.all
|
12
|
+
|
13
|
+
get :index, use_route: "trancelaion_center"
|
14
|
+
expect(assigns(:categories)).to eq(categories)
|
15
|
+
expect(response).to render_template(:index)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "GET show" do
|
20
|
+
it "assigns @category & render show template" do
|
21
|
+
category = FactoryGirl.create(:category)
|
22
|
+
|
23
|
+
get :show, id: category.id, use_route: "trancelaion_center"
|
24
|
+
expect(assigns(:category)).to eq(category)
|
25
|
+
expect(response).to render_template(:show)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "GET more_keys" do
|
30
|
+
it "assigns @category & render keys", :js => true do
|
31
|
+
category = FactoryGirl.create(:category)
|
32
|
+
get :more_keys, category_id: category.id, format: :js, use_route: "trancelaion_center"
|
33
|
+
expect(response).to render_template(:keys)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "GET destroy" do
|
38
|
+
it "assigns @category & render index" do
|
39
|
+
category = FactoryGirl.create(:category)
|
40
|
+
get :destroy, id: category.id, use_route: "trancelaion_center"
|
41
|
+
expect(Category.where(id: category.id)).to be_empty
|
42
|
+
expect(response).to redirect_to(:categories)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
module TranslationCenter
|
3
|
+
describe CenterController, :type => :controller do
|
4
|
+
let(:user) {FactoryGirl.create(:user)}
|
5
|
+
let(:translation_key) {FactoryGirl.create(:translation_key)}
|
6
|
+
before(:each) do
|
7
|
+
sign_in user
|
8
|
+
end
|
9
|
+
after(:all) do
|
10
|
+
FileUtils.rm_r("config/locales")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "GET set_language_from" do
|
14
|
+
it "should set language the user is translating from & render nothing" do
|
15
|
+
get :set_language_from, lang: "en", use_route: "trancelaion_center"
|
16
|
+
expect(I18n.locale).to eq :en
|
17
|
+
expect(response.body).to be_blank
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "GET set_language_to" do
|
22
|
+
it "should set language the user is translating to & redirect to root" do
|
23
|
+
get :set_language_to, lang: "ar", use_route: "trancelaion_center"
|
24
|
+
expect(session[:lang_to]).to eq :ar
|
25
|
+
expect(response).to redirect_to(:root)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should render nothing" do
|
29
|
+
get :set_language_to, lang: "ar", format: :js, use_route: "trancelaion_center"
|
30
|
+
expect(session[:lang_to]).to eq :ar
|
31
|
+
expect(response.body).to be_blank
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "GET dashboard" do
|
36
|
+
it "should set dashboard stats & render dashboard.html" do
|
37
|
+
get :dashboard, use_route: "trancelaion_center"
|
38
|
+
expect(assigns(:translations_changes).class.name).to eq "ActiveRecord::Relation"
|
39
|
+
expect(assigns(:total_pages).class.name).to eq "Fixnum"
|
40
|
+
expect(response).to render_template(:dashboard)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should render search_activity.html" do
|
44
|
+
get :dashboard, format: :js, use_route: "trancelaion_center"
|
45
|
+
expect(response).to render_template(:search_activity)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "GET search_activity" do
|
50
|
+
it "should render search_activity.js" do
|
51
|
+
get :search_activity, format: :js, use_route: "trancelaion_center"
|
52
|
+
expect(assigns(:translations_changes).class.name).to eq "ActiveRecord::Relation"
|
53
|
+
expect(assigns(:total_pages).class.name).to eq "Fixnum"
|
54
|
+
expect(response).to render_template(:search_activity)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "GET manage" do
|
59
|
+
Dir.mkdir "config/locales"
|
60
|
+
File.open( "config/locales/en.yml", "w+")
|
61
|
+
File.open( "config/locales/ar.yml", "w+")
|
62
|
+
it "should run yaml2db" do
|
63
|
+
get :manage, locale: "en", manage_action: "yaml2db", format: :js, use_route: "trancelaion_center"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should run db2yaml" do
|
67
|
+
|
68
|
+
get :manage, locale: "en", manage_action: "db2yaml", format: :js, use_route: "trancelaion_center"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should run yaml2db & render manage.js" do
|
72
|
+
get :manage, locale: "all", manage_action: "db2yaml", format: :js, use_route: "trancelaion_center"
|
73
|
+
expect(response).to render_template(:manage)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module TranslationCenter
|
3
|
+
describe TranslationKeysController, :type => :controller do
|
4
|
+
let(:user) {FactoryGirl.create(:user)}
|
5
|
+
let(:translation_key) {FactoryGirl.create(:translation_key)}
|
6
|
+
before(:each) do
|
7
|
+
sign_in user
|
8
|
+
end
|
9
|
+
describe "POST update_translation" do
|
10
|
+
it "should assigns @translation & render nothing" do
|
11
|
+
post :update_translation, translation_key_id: translation_key.id, format: :json, use_route: "trancelaion_center"
|
12
|
+
expect(assigns(:translation_key)).to eq translation_key
|
13
|
+
expect(response.body).to be_blank
|
14
|
+
end
|
15
|
+
it "should assigns @translation & render json" do
|
16
|
+
post :update_translation, translation_key_id: translation_key.id, value: "value value", format: :json, use_route: "trancelaion_center"
|
17
|
+
expect(assigns(:translation_key)).to eq translation_key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "GET translations" do
|
22
|
+
it "should assigns @translations sorted by votes & render translations.js" do
|
23
|
+
FactoryGirl.create(:translation, translation_key: translation_key)
|
24
|
+
# FactoryGirl.create(:translation, value: "value", translation_key: translation_key)
|
25
|
+
get :translations, translation_key_id: translation_key.id, sort_by: "votes", format: :js, use_route: "trancelaion_center"
|
26
|
+
expect(assigns(:translations).first.class.name).to eq "TranslationCenter::Translation"
|
27
|
+
expect(response).to render_template(:translations)
|
28
|
+
end
|
29
|
+
it "should assigns @translations sorted by created_at" do
|
30
|
+
FactoryGirl.create(:translation, translation_key: translation_key)
|
31
|
+
get :translations, translation_key_id: translation_key.id, format: :js, use_route: "trancelaion_center"
|
32
|
+
expect(assigns(:translations).first.class.name).to eq "TranslationCenter::Translation"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "GET show" do
|
37
|
+
it "should assign @translation_key & render show" do
|
38
|
+
get :show, id: translation_key.id, use_route: "trancelaion_center"
|
39
|
+
expect(assigns(:translation_key)).to eq translation_key
|
40
|
+
expect(response).to render_template(:show)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "PUT update" do
|
45
|
+
it "should assign @translation_key" do
|
46
|
+
put :update, id: translation_key.id, format: :json, use_route: "trancelaion_center"
|
47
|
+
expect(assigns(:translation_key)).to eq translation_key
|
48
|
+
expect(TranslationKey.find(translation_key).name).to eq translation_key.name
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should assign @translation_key & update value" do
|
52
|
+
put :update, id: translation_key.id, format: :json, value: "new value", use_route: "trancelaion_center"
|
53
|
+
expect(assigns(:translation_key)).to eq translation_key
|
54
|
+
expect(TranslationKey.find(translation_key).name).to eq "new value"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "POST destroy" do
|
59
|
+
it "should assign translation & render destroy.js" do
|
60
|
+
delete :destroy, id: translation_key.id, format: :js, use_route: "trancelaion_center"
|
61
|
+
expect(assigns(:category)).to eq translation_key.category
|
62
|
+
expect(assigns(:translation_key)).to eq translation_key
|
63
|
+
expect(TranslationKey.where(id: translation_key.id)).to be_empty
|
64
|
+
expect(response).to render_template(:destroy)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should assign render categories/show.html" do
|
68
|
+
delete :destroy, id: translation_key.id, use_route: "trancelaion_center"
|
69
|
+
expect(response).to redirect_to(translation_key.category)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "GET search" do
|
74
|
+
it "should assign translations & render search" do
|
75
|
+
get :search, search_key_name: translation_key.name, use_route: "trancelaion_center"
|
76
|
+
expect(assigns(:translation_key)).to eq translation_key
|
77
|
+
expect(response).to redirect_to(translation_key)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should render search.js" do
|
81
|
+
get :search, query: " ", format: :json, use_route: "trancelaion_center"
|
82
|
+
expect(assigns(:key_names).class.name).to eq "ActiveRecord::Relation"
|
83
|
+
expect(response).not_to redirect_to(translation_key)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|