Skip to content
Browse files

Swapped protected_attributes for strong params

  • Loading branch information...
1 parent 7e6223a commit 8a590d2ab5b69f28e004c7233b3fc707b35e913f @jmccartie jmccartie committed Jan 2, 2014
View
2 .ruby-version
@@ -1 +1 @@
-ruby-2.0.0-p247
+2.0.0-p353
View
1 Gemfile
@@ -4,7 +4,6 @@ gem "rails", "4.0.2"
gem 'will_paginate'
gem 'safe_yaml', '>= 0.8.6'
-gem "protected_attributes", "~> 1.0.5"
group 'test' do
gem 'capybara'
View
3 Gemfile.lock
@@ -61,8 +61,6 @@ GEM
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
polyglot (0.3.3)
- protected_attributes (1.0.5)
- activemodel (>= 4.0.1, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
@@ -118,7 +116,6 @@ DEPENDENCIES
factory_girl_rails
launchy
mocha
- protected_attributes (~> 1.0.5)
rails (= 4.0.2)
safe_yaml (>= 0.8.6)
selenium-webdriver
View
17 app/controllers/tolk/locales_controller.rb
@@ -24,7 +24,7 @@ def show
end
def update
- @locale.translations_attributes = params[:translations]
+ @locale.translations_attributes = translation_params
@locale.save
redirect_to request.referrer
end
@@ -39,7 +39,7 @@ def updated
end
def create
- Tolk::Locale.create!(params[:tolk_locale])
+ Tolk::Locale.create!(locale_params)
redirect_to :action => :index
end
@@ -71,5 +71,18 @@ def stats
def find_locale
@locale = Tolk::Locale.where('UPPER(name) = UPPER(?)', params[:id]).first!
end
+
+ def locale_params
+ params.require(:tolk_locale).permit(:name)
+ end
+
+ # TODO: whitelist incoming translation params
+ # translation permitted params: :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
+ # test params: "translations"=>[{"id"=>"", "phrase_id"=>"8", "locale_id"=>"5", "text"=>"Dead men don't bite"}, {"id"=>"", "phrase_id"=>"7", "locale_id"=>"5", "text"=>""}]
+ def translation_params
+ params.require(:translations)
+ end
+
+
end
end
View
1 app/models/tolk/locale.rb
@@ -15,7 +15,6 @@ def self._dump_path
accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
before_validation :remove_invalid_translations_from_target, :on => :update
- attr_accessible :name
cattr_accessor :locales_config_path
self.locales_config_path = self._dump_path
View
2 app/models/tolk/phrase.rb
@@ -2,8 +2,6 @@ module Tolk
class Phrase < ActiveRecord::Base
self.table_name = "tolk_phrases"
- attr_accessible :key
-
validates_uniqueness_of :key
cattr_accessor :per_page
View
4 app/models/tolk/translation.rb
@@ -15,8 +15,6 @@ class Translation < ActiveRecord::Base
belongs_to :locale, :class_name => 'Tolk::Locale'
validates_presence_of :locale_id
- attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
-
before_save :set_primary_updated
before_save :set_previous_text
@@ -156,7 +154,7 @@ def check_matching_variables
end
end
end
-
+
def validate_text_not_nil
return unless text.nil?
errors.add :text, :blank
View
8 test/integration/translation_process_test.rb
@@ -43,21 +43,21 @@ def test_search_phrase_within_key
# Adding a new translation
pirate_path = tolk.locale_path(locale)
visit pirate_path
-
+
fill_in 'q', :with => 'hello_country'
fill_in 'k', :with => 'nested'
-
+
click_button 'Search'
assert_equal true, page.has_selector?('td.translation', :count => 1)
end
-
+
private
def fill_in_first_translation(with_hash)
within(:xpath, '//table[@class = "translations"]//tr[2]/td[@class = "translation"][1]') do
fill_in 'translations[][text]', with_hash
end
-
+
end
def add_locale(name)
View
1 tolk.gemspec
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.add_dependency('will_paginate')
- s.add_dependency('protected_attributes')
s.add_dependency('safe_yaml', "~> 0.8")
if File.exists?('UPGRADING')
s.post_install_message = File.read("UPGRADING")

0 comments on commit 8a590d2

Please sign in to comment.
Something went wrong with that request. Please try again.