From b16f309aca06c83006db41f15ed14cd44f3c4f31 Mon Sep 17 00:00:00 2001 From: Steven Hancock Date: Fri, 11 May 2012 02:34:15 -0700 Subject: [PATCH 1/4] Upgrade Rails Admin to latest gem This gives us a clean fix for the Kaminari vs. Will Paginate issues and fixes a few other little bugs in Rails Admin. fixes #3210 --- Gemfile | 2 +- Gemfile.lock | 16 ++++++++-------- config/initializers/rails_admin.rb | 19 ++++++------------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 37baada1f..2ca5f9b53 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'newrelic_rpm' gem "rpm_contrib", "~> 2.1.7" group :production do # we don't install these on travis to speed up test runs - gem 'rails_admin' + gem 'rails_admin', '~> 0.0.2' gem 'rack-ssl', :require => 'rack/ssl' gem 'rack-rewrite', '~> 1.2.1', :require => false gem 'rack-piwik', :require => 'rack/piwik' diff --git a/Gemfile.lock b/Gemfile.lock index cd58577a1..152f632f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -161,7 +161,7 @@ GEM erubis (2.7.0) eventmachine (1.0.0.beta.4) excon (0.13.2) - execjs (1.3.0) + execjs (1.3.2) multi_json (~> 1.0) factory_girl (2.6.4) activesupport (>= 2.3.9) @@ -216,7 +216,7 @@ GEM guard-spork (0.5.2) guard (>= 0.10.0) spork (>= 0.8.4) - haml (3.1.4) + haml (3.1.5) handlebars_assets (0.4.1) execjs (>= 1.2.9) sprockets (>= 2.0.3) @@ -250,7 +250,7 @@ GEM jquery-ui-rails (0.2.2) jquery-rails railties (>= 3.1.0) - json (1.6.6) + json (1.7.1) jwt (0.1.4) json (>= 1.2.4) kaminari (0.13.0) @@ -357,13 +357,13 @@ GEM railties (= 3.1.4) rails-i18n (0.6.3) i18n (~> 0.5) - rails_admin (0.0.1) + rails_admin (0.0.2) bbenezech-nested_form (~> 0.0.6) bootstrap-sass (~> 2.0) builder (~> 3.0) coffee-rails (~> 3.1) haml (~> 3.1) - jquery-rails (>= 1.0) + jquery-rails (>= 1.0.17) jquery-ui-rails (~> 0.2.2) kaminari (~> 0.12) rack-pjax (~> 0.5) @@ -424,7 +424,7 @@ GEM ruby-oembed (0.8.7) ruby-progressbar (0.0.10) rubyzip (0.9.8) - sass (3.1.15) + sass (3.1.17) sass-rails (3.1.4) actionpack (~> 3.1.0) railties (~> 3.1.0) @@ -443,7 +443,7 @@ GEM rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) spork (1.0.0rc2) - sprockets (2.0.3) + sprockets (2.0.4) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) @@ -563,7 +563,7 @@ DEPENDENCIES rack-ssl rails (= 3.1.4) rails-i18n - rails_admin + rails_admin (~> 0.0.2) rails_autolink redcarpet (= 2.0.1) remotipart (~> 1.0) diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index 439c191a1..c370ffd79 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -1,6 +1,12 @@ # RailsAdmin config file. Generated on March 24, 2012 15:34 # See github.com/sferik/rails_admin for more informations if Rails.env.production? +# Recommended way to deal with Kaminari vs. WillPaginate issues +if defined?(WillPaginate) + Kaminari.configure do |config| + config.page_method_name = :per_page_kaminari + end +end RailsAdmin.config do |config| config.authorize_with do redirect_to main_app.root_path unless current_user.try(:admin?) @@ -1128,17 +1134,4 @@ RailsAdmin.config do |config| # update do; end # end end -if defined?(WillPaginate) - module WillPaginate - module ActiveRecord - module RelationMethods - def per(value = nil) per_page(value) end - def total_count() count end - end - end - module CollectionMethods - alias_method :num_pages, :total_pages - end - end -end end \ No newline at end of file From 7a6d325f64254f515d32620f126978c9b37a2222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Fri, 11 May 2012 14:23:05 +0200 Subject: [PATCH 2/4] looks like there are sometimes objects passed into post presenter that respond to root while root is nil --- app/presenters/post_presenter.rb | 4 ++-- spec/presenters/post_presenter_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 819be652b..40b2fb954 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -60,7 +60,7 @@ class PostPresenter end def root - PostPresenter.new(@post.root, current_user).as_json if @post.respond_to?(:root) + PostPresenter.new(@post.root, current_user).as_json if @post.respond_to?(:root) && @post.root.present? end def user_like @@ -102,4 +102,4 @@ class PostInteractionPresenter element.as_api_response(:backbone) end end -end \ No newline at end of file +end diff --git a/spec/presenters/post_presenter_spec.rb b/spec/presenters/post_presenter_spec.rb index 2e87f2bb9..0d3d205e8 100644 --- a/spec/presenters/post_presenter_spec.rb +++ b/spec/presenters/post_presenter_spec.rb @@ -42,7 +42,17 @@ describe PostPresenter do @unauthenticated_presenter.user_reshare.should be_nil end end - + + describe '#root' do + it 'does not raise if the root does not exists' do + reshare = Factory :reshare + reshare.root = nil + expect { + PostPresenter.new(reshare).root + }.to_not raise_error + end + end + describe '#next_post_path' do it 'returns a string of the users next post' do @presenter.next_post_path.should == "#{Rails.application.routes.url_helpers.post_path(@sm)}/next" @@ -71,4 +81,4 @@ describe PostPresenter do end end end -end \ No newline at end of file +end From 6cf163766a18b5a5bcdd27c8eb53ed23040a737b Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Fri, 11 May 2012 21:10:37 +0200 Subject: [PATCH 3/4] install script now checks for proper rvm/ruby and js runtime [ci skip] --- script/install.sh | 120 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/script/install.sh b/script/install.sh index 23092e7da..5b6d3d401 100755 --- a/script/install.sh +++ b/script/install.sh @@ -54,6 +54,13 @@ D_DB_USER="diaspora" D_DB_PASS="diaspora" +D_RUBY_VERSION="1.9.2-p290" + +#### INTERNAL VARS #### + +RVM_DETECTED=false +JS_RUNTIME_DETECTED=false + #### #### # # # FUNCTIONS, etc. # @@ -93,6 +100,11 @@ error() { exit 1 } +# check for functions +fn_exists() { + type -t $1 | grep -q 'function' +} + # shell interactive or not interactive_check() { fd=0 #stdin @@ -133,8 +145,20 @@ For more details check out https://rvm.io// EOT rvm_check() { echo -n "checking for rvm... " - rvm >/dev/null 2>&1 - if [ $? -eq 0 ]; then + fn_exists rvm + if [ $? -eq 0 ] ; then + RVM_DETECTED=true + + # seems we don't have it loaded, try to do so + elif [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then + source "$HOME/.rvm/scripts/rvm" >/dev/null 2>&1 + RVM_DETECTED=true + elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then + source "/usr/local/rvm/scripts/rvm" >/dev/null 2>&1 + RVM_DETECTED=true + fi + + if $RVM_DETECTED ; then echo "found" else echo "not found" @@ -144,6 +168,97 @@ rvm_check() { echo "" } +# prepare ruby with rvm +install_or_use_ruby() { + if ! $RVM_DETECTED ; then + return + fi + + # make sure we have the correct ruby version available + echo -n "checking your ruby version... " + rvm use $D_RUBY_VERSION >/dev/null 2>&1 + if [ $? -ne 0 ] ; then + echo "not ok" + rvm install $D_RUBY_VERSION >/dev/null 2>&1 + else + echo "ok" + fi + + echo "" +} + +# trust and load rvmrc +# do this in a directory that has a .rvmrc, only :) +load_rvmrc() { + if ! $RVM_DETECTED ; then + return + fi + + # trust rvmrc + rvm rvmrc is_trusted + if [ $? -ne 0 ] ; then + rvm rvmrc trust + fi + + # load .rvmrc + echo -n "loading .rvmrc ... " + rvm rvmrc load + if [ $? -eq 0 ] ; then + echo "ok" + else + echo "not ok" + fi + echo "" +} + +# we need a valid js runtime... +define JS_RT_MSG <<'EOT' +This script was unable to find a JavaScript runtime compatible to ExecJS on +your system. We recommend you install either Node.js or TheRubyRacer, since +those have been proven to work. + +Node.js -- http://nodejs.org/ +TheRubyRacer -- https://github.com/cowboyd/therubyracer + +For more information on ExecJS, visit +-- https://github.com/sstephenson/execjs +EOT +js_runtime_check() { + echo -n "checking for a JavaScript runtime... " + + # Node.js + which node >/dev/null 2>&1 + if [ $? -eq 0 ] ; then + JS_RUNTIME_DETECTED=true + fi + + # TheRubyRacer + gem which v8 >/dev/null 2>&1 + if [ $? -eq 0 ] ; then + JS_RUNTIME_DETECTED=true + fi + + ## + # add your favourite js runtime here... + ## + + if $JS_RUNTIME_DETECTED ; then + echo "ok" + else + echo "not ok" + echo $JS_RT_MSG + error "can't continue without a JS runtime" + fi + echo "" +} + +# make ourselves comfy +prepare_install_env() { + install_or_use_ruby + load_rvmrc + js_runtime_check +} + # do some sanity checking sane_environment_check() { binaries_check @@ -250,6 +365,7 @@ git_stuff_check # goto working directory run_or_error "cd \"$D_GIT_CLONE_PATH\"" +prepare_install_env # configure database setup From 2d810a0c43c8b42a3db93931b16ebd8feab3582b Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Fri, 11 May 2012 21:20:56 +0200 Subject: [PATCH 4/4] missing quotes... [ci skip] --- script/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/install.sh b/script/install.sh index 5b6d3d401..13dd9738f 100755 --- a/script/install.sh +++ b/script/install.sh @@ -246,7 +246,7 @@ js_runtime_check() { echo "ok" else echo "not ok" - echo $JS_RT_MSG + echo "$JS_RT_MSG" error "can't continue without a JS runtime" fi echo ""