diff --git a/app/controllers/lit/localizations_controller.rb b/app/controllers/lit/localizations_controller.rb index 5a4eb628..a7961827 100644 --- a/app/controllers/lit/localizations_controller.rb +++ b/app/controllers/lit/localizations_controller.rb @@ -32,9 +32,11 @@ def find_localization def clear_params if defined?(::ActionController::StrongParameters) - params.require(:localization).permit(:translated_value, :locale_id) + clear_params = params.require(:localization).permit(:translated_value, :locale_id) + clear_params.merge! params.require(:localization).permit(:translated_value => []) # allow translated_value to be an array + clear_params else - params[:localization] + params[:localization].is_a?(Hash) ? params[:localization].slice(:translated_value, :locale_id) : {} end end end diff --git a/test/fixtures/lit_locales.yml b/test/fixtures/lit/locales.yml similarity index 100% rename from test/fixtures/lit_locales.yml rename to test/fixtures/lit/locales.yml diff --git a/test/fixtures/lit/localization_keys.yml b/test/fixtures/lit/localization_keys.yml new file mode 100644 index 00000000..56edba80 --- /dev/null +++ b/test/fixtures/lit/localization_keys.yml @@ -0,0 +1,14 @@ +hello_world: + localization_key: 'scopes.hello_world' + created_at: <%= Time.now %> + updated_at: <%= Time.now %> + +array: + localization_key: 'scopes.array' + created_at: <%= Time.now %> + updated_at: <%= Time.now %> + +string: + localization_key: 'scopes.string' + created_at: <%= Time.now %> + updated_at: <%= Time.now %> diff --git a/test/fixtures/lit/localizations.yml b/test/fixtures/lit/localizations.yml index 81c944b7..411dbdc6 100644 --- a/test/fixtures/lit/localizations.yml +++ b/test/fixtures/lit/localizations.yml @@ -1,17 +1,23 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html -one: - locale: - localization_key: - translated_value: MyText - default_value: MyText +string: + locale: en + localization_key: array + translated_value: value + default_value: value created_at: <%= Time.now %> updated_at: <%= Time.now %> -two: - locale: - localization_key: - translated_value: MyText - default_value: MyText +array: + locale: en + localization_key: array + translated_value: + - one + - two + - three + default_value: + - one + - two + - three created_at: <%= Time.now %> updated_at: <%= Time.now %> diff --git a/test/fixtures/lit_sources.yml b/test/fixtures/lit/sources.yml similarity index 100% rename from test/fixtures/lit_sources.yml rename to test/fixtures/lit/sources.yml diff --git a/test/fixtures/lit_localization_keys.yml b/test/fixtures/lit_localization_keys.yml deleted file mode 100644 index af8ab252..00000000 --- a/test/fixtures/lit_localization_keys.yml +++ /dev/null @@ -1,5 +0,0 @@ -hello_world: - localization_key: 'scopes.hello_world' - created_at: <%= Time.now %> - updated_at: <%= Time.now %> - diff --git a/test/functional/lit/incomming_localizations_controller_test.rb b/test/functional/lit/incomming_localizations_controller_test.rb index a1570aa4..1ad01c5f 100644 --- a/test/functional/lit/incomming_localizations_controller_test.rb +++ b/test/functional/lit/incomming_localizations_controller_test.rb @@ -3,7 +3,7 @@ module Lit class IncommingLocalizationsControllerTest < ActionController::TestCase - fixtures :lit_sources + fixtures "lit/sources" set_fixture_class :lit_sources => Lit::Source def setup Lit.authentication_function = nil diff --git a/test/functional/lit/localizations_controller_test.rb b/test/functional/lit/localizations_controller_test.rb new file mode 100644 index 00000000..3890433a --- /dev/null +++ b/test/functional/lit/localizations_controller_test.rb @@ -0,0 +1,47 @@ +require 'test_helper' + +module Lit + class LocalizationsControllerTest < ActionController::TestCase + fixtures :all + + setup do + Lit.authentication_function = nil + @routes = Lit::Engine.routes + @localization = lit_localizations(:array) + end + + test "should get edit" do + get :edit, :localization_key_id => @localization.localization_key.id, :id => @localization.id, :format => :js + assert_response :success + assert_not_nil assigns(:localization) + end + + test "should get previous_versions" do + get :previous_versions, :localization_key_id => @localization.localization_key.id, :id => @localization.id, + :format => :js + assert_response :success + assert_not_nil assigns(:localization) + assert_not_nil assigns(:versions) + end + + test "should update localization when translated_value is a string" do + @localization = lit_localizations(:string) + put :update, :localization_key_id => @localization.localization_key.id, :id => @localization.id, + :localization => { :translated_value => "new-value", :locale_id => @localization.locale_id }, :format => :js + assert_response :success + @localization.reload + assert_equal "new-value", @localization.translated_value + end + + test "should update localization when translated_value is a array" do + @localization = lit_localizations(:array) + put :update, :localization_key_id => @localization.localization_key.id, :id => @localization.id, + :localization => { :translated_value => ["three", "two", "one"], :locale_id => @localization.locale_id }, + :format => :js + assert_response :success + @localization.reload + assert_equal ["three", "two", "one"], @localization.translated_value + end + + end +end diff --git a/test/functional/lit/sources_controller_test.rb b/test/functional/lit/sources_controller_test.rb index c83a2d5f..2a40acf8 100644 --- a/test/functional/lit/sources_controller_test.rb +++ b/test/functional/lit/sources_controller_test.rb @@ -3,8 +3,8 @@ module Lit class SourcesControllerTest < ActionController::TestCase - fixtures :lit_sources - set_fixture_class :lit_sources => Lit::Source + fixtures "lit/sources" + setup do Lit.authentication_function = nil @routes = Lit::Engine.routes diff --git a/test/unit/lit/locale_test.rb b/test/unit/lit/locale_test.rb index 4bb31d8e..3eaa8909 100644 --- a/test/unit/lit/locale_test.rb +++ b/test/unit/lit/locale_test.rb @@ -2,8 +2,8 @@ module Lit class LocaleTest < ActiveSupport::TestCase - fixtures :lit_locales - set_fixture_class :lit_locales => Lit::Locale + fixtures 'lit/locales' + test "uniqueness checking" do l = lit_locales(:pl) locale = Lit::Locale.new({:locale=>l.locale}) diff --git a/test/unit/lit/localization_key_test.rb b/test/unit/lit/localization_key_test.rb index 9ac593fb..55b85556 100644 --- a/test/unit/lit/localization_key_test.rb +++ b/test/unit/lit/localization_key_test.rb @@ -2,8 +2,8 @@ module Lit class LocalizationKeyTest < ActiveSupport::TestCase - fixtures :lit_localization_keys - set_fixture_class :lit_localization_keys => Lit::LocalizationKey + fixtures "lit/localization_keys" + test "uniqueness checking" do l = lit_localization_keys(:hello_world) lk = Lit::LocalizationKey.new({:localization_key=>l.localization_key})