Commit 3559327655dc6ee0b12130728261ccca6e4245e5
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'master' into stable
Showing
5 changed files
with
68 additions
and
14 deletions
Show diff stats
app/helpers/application_helper.rb
| @@ -1380,7 +1380,7 @@ module ApplicationHelper | @@ -1380,7 +1380,7 @@ module ApplicationHelper | ||
| 1380 | # are old things that do not support it we are keeping this hot spot. | 1380 | # are old things that do not support it we are keeping this hot spot. |
| 1381 | html = @plugins.pipeline(:parse_content, html, source).first | 1381 | html = @plugins.pipeline(:parse_content, html, source).first |
| 1382 | end | 1382 | end |
| 1383 | - html.html_safe | 1383 | + html && html.html_safe |
| 1384 | end | 1384 | end |
| 1385 | 1385 | ||
| 1386 | def convert_macro(html, source) | 1386 | def convert_macro(html, source) |
db/migrate/20140724134601_fix_yaml_encoding.rb
| 1 | class FixYamlEncoding < ActiveRecord::Migration | 1 | class FixYamlEncoding < ActiveRecord::Migration |
| 2 | def self.up | 2 | def self.up |
| 3 | - fix_encoding(Block, 'settings') | ||
| 4 | - fix_encoding(Product, 'data') | ||
| 5 | - fix_encoding(Environment, 'settings') | ||
| 6 | - fix_encoding(Profile, 'data') | ||
| 7 | - fix_encoding(ActionTracker::Record, 'params') | ||
| 8 | - fix_encoding(Article, 'setting') | ||
| 9 | - fix_encoding(Task, 'data') | 3 | + ActiveRecord::Base.transaction do |
| 4 | + fix_encoding(Environment, 'settings') | ||
| 5 | + fix_encoding(Profile, 'data') | ||
| 6 | + fix_encoding(Product, 'data') | ||
| 7 | + fix_encoding(ActionTracker::Record, 'params') | ||
| 8 | + fix_encoding(Article, 'setting') | ||
| 9 | + fix_encoding(Task, 'data') | ||
| 10 | + fix_encoding(Block, 'settings') | ||
| 11 | + end | ||
| 10 | end | 12 | end |
| 11 | 13 | ||
| 12 | def self.down | 14 | def self.down |
| @@ -16,15 +18,34 @@ class FixYamlEncoding < ActiveRecord::Migration | @@ -16,15 +18,34 @@ class FixYamlEncoding < ActiveRecord::Migration | ||
| 16 | private | 18 | private |
| 17 | 19 | ||
| 18 | def self.fix_encoding(model, param) | 20 | def self.fix_encoding(model, param) |
| 19 | - result = model.find(:all, :conditions => "#{param} LIKE '%!binary%'") | 21 | + result = model.all |
| 20 | puts "Fixing #{result.count} rows of #{model} (#{param})" | 22 | puts "Fixing #{result.count} rows of #{model} (#{param})" |
| 21 | - result.each {|r| r.update_column(param, deep_fix(r.send(param)).to_yaml)} | 23 | + result.each do |r| |
| 24 | + begin | ||
| 25 | + yaml = r.send(param) | ||
| 26 | + # if deserialization failed then a string is returned | ||
| 27 | + if yaml.is_a? String | ||
| 28 | + yaml.gsub! ': `', ': ' | ||
| 29 | + yaml = YAML.load yaml | ||
| 30 | + end | ||
| 31 | + r.update_column param, deep_fix(yaml).to_yaml | ||
| 32 | + rescue => e | ||
| 33 | + puts "FAILED #{r.inspect}" | ||
| 34 | + puts e.message | ||
| 35 | + end | ||
| 36 | + end | ||
| 22 | end | 37 | end |
| 23 | 38 | ||
| 24 | def self.deep_fix(hash) | 39 | def self.deep_fix(hash) |
| 25 | hash.each do |value| | 40 | hash.each do |value| |
| 26 | - value.force_encoding('UTF-8') if value.is_a?(String) && !value.frozen? && value.encoding == Encoding::ASCII_8BIT | ||
| 27 | deep_fix(value) if value.respond_to?(:each) | 41 | deep_fix(value) if value.respond_to?(:each) |
| 42 | + if value.is_a? String and not value.frozen? | ||
| 43 | + if value.encoding == Encoding::ASCII_8BIT | ||
| 44 | + value.force_encoding "utf-8" | ||
| 45 | + else | ||
| 46 | + value.encode!("iso-8859-1").force_encoding("utf-8") | ||
| 47 | + end | ||
| 48 | + end | ||
| 28 | end | 49 | end |
| 29 | end | 50 | end |
| 30 | 51 |
plugins/remote_user/test/functional/remote_user_plugin_test.rb
| @@ -61,6 +61,8 @@ class AccountControllerTest < ActionController::TestCase | @@ -61,6 +61,8 @@ class AccountControllerTest < ActionController::TestCase | ||
| 61 | end | 61 | end |
| 62 | 62 | ||
| 63 | should 'create a new user with remote_user_data even if there is a logged user but the remote user is different' do | 63 | should 'create a new user with remote_user_data even if there is a logged user but the remote user is different' do |
| 64 | + users = User.count | ||
| 65 | + | ||
| 64 | user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | 66 | user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') |
| 65 | user.activate | 67 | user.activate |
| 66 | 68 | ||
| @@ -71,7 +73,7 @@ class AccountControllerTest < ActionController::TestCase | @@ -71,7 +73,7 @@ class AccountControllerTest < ActionController::TestCase | ||
| 71 | @request.env["HTTP_REMOTE_USER_DATA"] = '{"email":"another_user@domain.com", "name":"Another User"}' | 73 | @request.env["HTTP_REMOTE_USER_DATA"] = '{"email":"another_user@domain.com", "name":"Another User"}' |
| 72 | get :index | 74 | get :index |
| 73 | 75 | ||
| 74 | - assert_equal 2, User.count | 76 | + assert_equal users + 2, User.count |
| 75 | assert_equal "another_user", User.last.login | 77 | assert_equal "another_user", User.last.login |
| 76 | assert_equal true, User.last.activated? | 78 | assert_equal true, User.last.activated? |
| 77 | assert_equal User.last.id, session[:user] | 79 | assert_equal User.last.id, session[:user] |
| @@ -96,6 +98,8 @@ class AccountControllerTest < ActionController::TestCase | @@ -96,6 +98,8 @@ class AccountControllerTest < ActionController::TestCase | ||
| 96 | end | 98 | end |
| 97 | 99 | ||
| 98 | should 'create a new user without remote_user_data even if there is a logged user but the remote user is different' do | 100 | should 'create a new user without remote_user_data even if there is a logged user but the remote user is different' do |
| 101 | + users = User.count | ||
| 102 | + | ||
| 99 | user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | 103 | user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') |
| 100 | user.activate | 104 | user.activate |
| 101 | 105 | ||
| @@ -104,7 +108,7 @@ class AccountControllerTest < ActionController::TestCase | @@ -104,7 +108,7 @@ class AccountControllerTest < ActionController::TestCase | ||
| 104 | @request.env["HTTP_REMOTE_USER"] = 'another_user' | 108 | @request.env["HTTP_REMOTE_USER"] = 'another_user' |
| 105 | get :index | 109 | get :index |
| 106 | 110 | ||
| 107 | - assert_equal 2, User.count | 111 | + assert_equal users + 2, User.count |
| 108 | assert_equal "another_user", User.last.login | 112 | assert_equal "another_user", User.last.login |
| 109 | assert_equal true, User.last.activated? | 113 | assert_equal true, User.last.activated? |
| 110 | assert_equal User.last.id, session[:user] | 114 | assert_equal User.last.id, session[:user] |
script/development
| @@ -5,8 +5,13 @@ set -e | @@ -5,8 +5,13 @@ set -e | ||
| 5 | export RAILS_ENV=development | 5 | export RAILS_ENV=development |
| 6 | 6 | ||
| 7 | stop() { | 7 | stop() { |
| 8 | + echo "Stopping ..." | ||
| 8 | ./script/delayed_job stop | 9 | ./script/delayed_job stop |
| 9 | ./script/feed-updater stop | 10 | ./script/feed-updater stop |
| 11 | + if [ -f tmp/pids/thin.pid ]; then | ||
| 12 | + kill -9 $(cat tmp/pids/thin.pid) | ||
| 13 | + rm -f tmp/pids/thin.pid | ||
| 14 | + fi | ||
| 10 | exit | 15 | exit |
| 11 | } | 16 | } |
| 12 | 17 | ||
| @@ -15,7 +20,18 @@ start() { | @@ -15,7 +20,18 @@ start() { | ||
| 15 | ./script/feed-updater start | 20 | ./script/feed-updater start |
| 16 | ./script/delayed_job start | 21 | ./script/delayed_job start |
| 17 | trap stop INT TERM | 22 | trap stop INT TERM |
| 18 | - rails s $@ | 23 | + if [ -z "$RAILS_RELATIVE_URL_ROOT" ]; then |
| 24 | + rails s $@ | ||
| 25 | + else | ||
| 26 | + mkdir -p log | ||
| 27 | + touch log/development.log | ||
| 28 | + thin \ | ||
| 29 | + --prefix "$RAILS_RELATIVE_URL_ROOT" \ | ||
| 30 | + --pid tmp/pids/thin.pid \ | ||
| 31 | + --daemonize \ | ||
| 32 | + start | ||
| 33 | + tail -n 0 -f log/development.log || true | ||
| 34 | + fi | ||
| 19 | } | 35 | } |
| 20 | 36 | ||
| 21 | start $@ | 37 | start $@ |