Skip to content

Commit

Permalink
Merge pull request prograils#14 from Bonias/fix-array-translations-up…
Browse files Browse the repository at this point in the history
…dating

Fixed array translations updating - strong parameters allowed only strings.
  • Loading branch information
mlitwiniuk committed Oct 16, 2013
2 parents 93f22c4 + 17416c0 commit 97084d3
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 24 deletions.
6 changes: 4 additions & 2 deletions app/controllers/lit/localizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions test/fixtures/lit/localization_keys.yml
Original file line number Diff line number Diff line change
@@ -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 %>
26 changes: 16 additions & 10 deletions test/fixtures/lit/localizations.yml
Original file line number Diff line number Diff line change
@@ -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 %>
File renamed without changes.
5 changes: 0 additions & 5 deletions test/fixtures/lit_localization_keys.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions test/functional/lit/localizations_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/functional/lit/sources_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lit/locale_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lit/localization_key_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 97084d3

Please sign in to comment.