diff options
36 files changed, 148 insertions, 105 deletions
diff --git a/.gitignore b/.gitignore index d7929e45e..83db620f2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ TAGS /public/*theme /vendor/bundle .bundle -.vagrant
\ No newline at end of file +.vagrant +bin/
\ No newline at end of file diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index b2c084739..249030537 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -74,10 +74,9 @@ class AdminUserController < AdminController def login_as @admin_user = User.find(params[:id]) # check user does exist - post_redirect = PostRedirect.new( :uri => main_url(user_url(@admin_user)), :user_id => @admin_user.id) + post_redirect = PostRedirect.new( :uri => main_url(user_url(@admin_user)), :user_id => @admin_user.id, :circumstance => "login_as" ) post_redirect.save! url = main_url(confirm_url(:email_token => post_redirect.email_token, :only_path => true)) - session[:user_id] = nil # Log out current (usually admin) user, so we get logged in as the other user redirect_to url end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 434f12a49..0ec8e206e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -151,8 +151,8 @@ class ApplicationController < ActionController::Base false end - # Called from test code, is a mimic of User.confirm, for use in following email - # links when in controller tests (since we don't have full integration tests that + # Called from test code, is a mimic of UserController.confirm, for use in following email + # links when in controller tests (though we also have full integration tests that # can work over multiple controllers) def test_code_redirect_by_email_token(token, controller_example_group) post_redirect = PostRedirect.find_by_email_token(token) @@ -178,7 +178,7 @@ class ApplicationController < ActionController::Base end def foi_fragment_cache_path(param) - path = File.join(RAILS_ROOT, 'cache', 'views', foi_fragment_cache_part_path(param)) + path = File.join(Rails.root, 'cache', 'views', foi_fragment_cache_part_path(param)) max_file_length = 255 - 35 # we subtract 35 because tempfile # adds on a variable number of # characters @@ -224,15 +224,15 @@ class ApplicationController < ActionController::Base post_redirect = PostRedirect.new(:uri => request.request_uri, :post_params => params, :reason_params => reason_params) post_redirect.save! - # 'modal' controls whether the sign-in form will be displayed in the typical full-blown - # page or on its own, useful for pop-ups + # 'modal' controls whether the sign-in form will be displayed in the typical full-blown + # page or on its own, useful for pop-ups redirect_to signin_url(:token => post_redirect.token, :modal => params[:modal]) return false end return true end - def authenticated_as_user?(user, reason_params) + def authenticated_as_user?(user, reason_params) reason_params[:user_name] = user.name reason_params[:user_url] = show_user_url(:url_name => user.url_name) if session[:user_id] @@ -274,6 +274,8 @@ class ApplicationController < ActionController::Base # XXX what is the built in Ruby URI munging function that can do this # choice of & vs. ? more elegantly than this dumb if statement? if uri.include?("?") + # XXX This looks odd. What would a fragment identifier be doing server-side? + # But it also looks harmless, so I’ll leave it just in case. if uri.include?("#") uri.sub!("#", "&post_redirect=1#") else diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 403cb9684..08726183e 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -182,7 +182,7 @@ class UserController < ApplicationController return end - if !User.stay_logged_in_on_redirect?(@user) + if !User.stay_logged_in_on_redirect?(@user) || post_redirect.circumstance == "login_as" @user = post_redirect.user @user.email_confirmed = true @user.save! diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 59cc86799..c9a6229a4 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -39,7 +39,7 @@ class PostRedirect < ActiveRecord::Base self.post_params_yaml = params.to_yaml end def post_params - if self.post_params_yaml.nil? + if self.post_params_yaml.nil? return {} end YAML.load(self.post_params_yaml) diff --git a/app/models/public_body.rb b/app/models/public_body.rb index a18af8c69..bc83f88f9 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -234,7 +234,12 @@ class PublicBody < ActiveRecord::Base end def update_url_name - self.url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') + preferred_name = self.short_or_long_name + if !preferred_name.nil? + # we test it's not nil, because sometimes a race condition + # means no name has been set yet + self.url_name = MySociety::Format.simplify_url_part(preferred_name, 'body') + end end # Return the short name if present, or else long name diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 3e12a6feb..1feb9c70b 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -27,7 +27,7 @@ class RawEmail < ActiveRecord::Base def directory request_id = self.incoming_message.info_request.id.to_s if ENV["RAILS_ENV"] == "test" - return File.join(RAILS_ROOT, 'files/raw_email_test') + return File.join(Rails.root, 'files/raw_email_test') else return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION', 'files/raw_emails'), diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 83cce9045..177a39241 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -40,7 +40,7 @@ class RequestMailer < ApplicationMailer :filename => "original.eml", :transfer_encoding => '7bit', :content_disposition => 'inline' @body = { :info_request => info_request, - :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') + :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } end diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 58d70ed86..b03055b5c 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -108,7 +108,7 @@ class TrackThing < ActiveRecord::Base end descriptions = [] if varieties.include? _("requests") - descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).join(_(' or '))) + descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).sort.join(_(' or '))) varieties -= [_("requests")] end if descriptions.empty? and varieties.empty? diff --git a/chef/cookbooks/alaveteli/recipes/default.rb b/chef/cookbooks/alaveteli/recipes/default.rb index a17ec7edd..49bac7ac4 100644 --- a/chef/cookbooks/alaveteli/recipes/default.rb +++ b/chef/cookbooks/alaveteli/recipes/default.rb @@ -67,7 +67,7 @@ bash "run bundle install" do end bash "bring rake into the PATH" do - code "ln -s #{path}/rake /usr/local/bin/rake" + code "ln -s #{node[:root]}/bin/rake /usr/local/bin/rake" not_if "[ -e /usr/local/bin/rake ] || [ -e /usr/bin/rake ]" end diff --git a/config.ru b/config.ru new file mode 100644 index 000000000..30b00bfa1 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require File.dirname(__FILE__) + '/config/environment' +run ActionController::Dispatcher.new diff --git a/config/environment.rb b/config/environment.rb index 7b6e8f5bc..e35194bc7 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -49,7 +49,7 @@ Rails::Initializer.run do |config| # config.plugins = %W( exception_notification ssl_requirement ) # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) + # config.load_paths += %W( #{Rails.root}/extras ) # Force all environments to use the same logger level # (by default production uses :info, the others :debug) diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 9ef2dddc1..bf40e99c1 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -12,6 +12,6 @@ ActionController::Base.session = { ActionController::Base.session_store = :cookie_store # Insert a bit of middleware code to prevent uneeded cookie setting. -require "#{RAILS_ROOT}/lib/whatdotheyknow/strip_empty_sessions" +require "#{Rails.root}/lib/whatdotheyknow/strip_empty_sessions" ActionController::Dispatcher.middleware.insert_before ActionController::Base.session_store, WhatDoTheyKnow::StripEmptySessions, :key => '_wdtk_cookie_session', :path => "/", :httponly => true diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 51da903b1..c01bbbe17 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -2,18 +2,26 @@ ## Highlighted features -* Ruby dependencies are now handled by Bundler +* Ruby dependencies are now handled by Bundler. ## Upgrade notes -* Existing installations will need to install the Bundler gem. See - `INSTALL.md` for details. - -* Because dependencies are now handled by Bundler, when you next run - the `rails-post-deploy` script, it will download, compile and - install various things. Part of this is compiling xapian, which may - take a *long* time (subsequent deployments should be much faster) - +* You should set aside a while to do this upgrade, as it will require + some manual intervention and a wait while dependencies compile: + + * Existing installations will need to install the Bundler gem. See + `INSTALL.md` for details. + + * Because dependencies are now handled by Bundler, when you next run + the `rails-post-deploy` script, it will download, compile and + install various things. Part of this is compiling xapian, which may + take a *long* time (subsequent deployments should be much faster) + +* As a side effect of using bundler, `rake` tasks (such as `rake spec` + and `rake db:migrate`) should now be prefixed with `bundle exec` + (e.g. `bundle exec rake spec`) to ensure they use the correct + bundled environment + # Version 0.5.1 ## Highlighted features diff --git a/doc/INSTALL-exim4.md b/doc/INSTALL-exim4.md index 82c1aba45..84f105c57 100644 --- a/doc/INSTALL-exim4.md +++ b/doc/INSTALL-exim4.md @@ -34,7 +34,7 @@ In `/etc/exim4/conf.d/transport/04_alaveteli`: user = ALAVETELI_USER group = ALAVETELI_USER -And, assuming you set `OPTION_INCOMING_EMAIL_PREFIX` in your config at +And, assuming you set `INCOMING_EMAIL_PREFIX` in your config at `config/general` to "foi+", create `config/aliases` with the following content: @@ -59,7 +59,11 @@ with `FORWARD_NONBOUNCE_RESPONSES_TO: 'raw_team@whatdotheyknow.com'` Finally, make sure you have `dc_use_split_config='true'` in `/etc/exim4/update-exim4.conf.conf`, and execute the command -`update-exim4.conf` +`update-exim4.conf`. + +NB: if the file `/etc/exim4/exim4.conf` exists then `update-exim4.conf` +will silently do nothing. Some distributions include this file. If +yours does, you will need to rename it before running `update-exim4.conf`. (You may also want to set `dc_eximconfig_configtype='internet'`, `dc_local_interfaces='0.0.0.0 ; ::1'`, and diff --git a/doc/INSTALL-vagrant.md b/doc/INSTALL-vagrant.md index 18db33c95..34a8ae30e 100644 --- a/doc/INSTALL-vagrant.md +++ b/doc/INSTALL-vagrant.md @@ -24,9 +24,9 @@ Usage ### Download, install and run VM -NOTE: This will download at least 400MB and take some time (30 minutes with a -broadband internet connection). This time and downloading is only required the -first time you run this command. +NOTE: This will download at least 400MB and take some time (30 minutes +with a broadband internet connection). The downloading is only +required the first time you run this command. You'll be asked for your password to sudo - this is required to create NFS shared folders. @@ -44,7 +44,7 @@ shared folders. ### Run the tests - bundle exec rake + bundle exec rake spec ### Start the development server diff --git a/doc/INSTALL.md b/doc/INSTALL.md index 35d64fc68..5cbad765c 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -6,7 +6,7 @@ deployment platform. Commands are intended to be run via the terminal or over ssh. As an aid to evaluation, there is an -[Amazon AMI](https://github.com/sebbacon/alaveteli/wiki/Alaveteli-ec2-amix) +[Amazon AMI](https://github.com/sebbacon/alaveteli/wiki/Alaveteli-ec2-ami) with all these steps configured. It is *not* production-ready. # Get Alaveteli @@ -27,21 +27,15 @@ branch: # Dev environment quickstart -To get a dev environment running quickly on Debian or Ubuntu, you can -use Chef. - -Alternatively, you can use Vagrant (which provisions a virtual machine -and installs Alaveteli there) on any platform supported by Vagrant. - -These quickstart methods are not currently recommended for production, -because they are still under development (and don't include memcached, -varnish, exim fonfiguration, etc). For production, you should follow -the steps below manually. +To get a dev environment running quickly you can use Vagrant (which +provisions a virtual machine and installs Alaveteli there) on any +platform supported by Vagrant. To install using Vagrant, see `INSTALL-vagrant.md`. -To install using chef, install chef (e.g. `apt-get install chef`) and -run: +You can also use chef to install directly into Debian (Ubuntu may work +but is not currently tested). To do so, first install chef +(e.g. `apt-get install chef`), then run: sudo chef-solo -c chef/solo.rb -j chef/solo.json @@ -57,7 +51,11 @@ packages by adding the following to `/etc/apt/sources.list` and running `apt-get update`: deb http://debian.mysociety.org squeeze main - + +If you don't set up that mySociety Debian source (e.g. if you're +running Ubuntu), you should comment out `wkhtmltopdf-static` from +`config/packages`, as it won't install in the next step + Now install the packages that are listed in config/packages using apt-get e.g.: @@ -65,10 +63,7 @@ e.g.: Some of the files also have a version number listed in config/packages - check that you have appropriate versions installed. Some also list -"|" and offer a choice of packages. If you've not set up the -mySociety Debian source (e.g. if you're running Ubuntu), you should -comment out `wkhtmltopdf-static` from `config/packages`, as it won't -install. +"|" and offer a choice of packages. # Step 2: Install Ruby dependencies @@ -203,7 +198,7 @@ is emailed to `CONTACT_EMAIL`. 1.9). A well-configured installation of this code will separately have had -Exim make a backup copy of the email in a separate mailbox, just in +the MTA make a backup copy of the email in a separate mailbox, just in case. # Step 6: Set up configs @@ -225,6 +220,9 @@ Interlock Rails plugin, to cache content using memcached. You probably don't want this in your development profile; the example `memcached.yml` file disables this behaviour. +As a precaution, you should probably set your `elinks` configuration +according to the Troubleshooting guide at the end of this document. + # Step 7: Deployment In the 'alaveteli' directory, run: @@ -233,23 +231,18 @@ In the 'alaveteli' directory, run: (This will need execute privs so `chmod 755` if necessary.) This sets up directory structures, creates logs, installs/updates themes, runs -database migrations, etc. You should run it after each new software -update. +database migrations, etc. **You should run it after each new software +update.** One of the things the script does is install dependencies (using `bundle install`). Note that the first time you run it, part of the `bundle install` that compiles `xapian-full` takes a *long* time! -On Debian, at least, the binaries installed by bundler are not put in -the system `PATH`; therefore, in order to run `rake` (needed for -deployments), you will need to do something like: - - ln -s /usr/lib/ruby/gems/1.8/bin/rake /usr/local/bin/ - -Or (Debian): - - ln -s /usr/lib/ruby/gems/1.8/bin/rake /usr/local/bin/ +The binaries installed by bundler are not put in the system `PATH`, +but in `$ALAVETELI_HOME/bin/`; therefore, in order to run `rake` +(needed for deployments), you will need to do something like: + ln -s `pwd`/bin/rake /usr/local/bin/ If you want some dummy data to play with, you can try loading the fixtures that the test suite uses into your development database. You @@ -271,8 +264,8 @@ Make sure everything looks OK: bundle exec rake spec If there are failures here, something has gone wrong with the -preceding steps (see the next section for a common problem and -workaround). You might be able to move on to the next step, depending +preceding steps (see the next section for common problems and +workarounds). You might be able to move on to the next step, depending on how serious they are, but ideally you should try to find out what's gone wrong. @@ -310,6 +303,9 @@ And send us the patch! # Step 11: Cron jobs `config/crontab.ugly` contains the cronjobs run on WhatDoTheyKnow. +These jobs are mostly to process queues: things that need reindexing, +email alerts that need sending out, etc. + It's in a strange templating format they use in mySociety. mySociety render the "ugly" file to reference absolute paths, and then drop it in `/etc/cron.d/` on the server. @@ -382,16 +378,19 @@ are evolving on the wiki. and then pipe it through the mailin script. A non-zero exit code means there was a problem. For example: + # get a valid email source (this example is from the text fixtures): $ cp spec/fixtures/files/incoming-request-plain.email /tmp/ + # substitute a magic email address in the existing To: header: $ perl -pi -e 's/^To:.*/To: <request-101-50929748@localhost>/' /tmp/incoming-request-plain.email + # now try piping this to the mailin script: $ ./script/mailin < /tmp/incoming-request-plain.email $ echo $? 75 The `mailin` script emails the details of any errors to - `CONTACT_EMAIL` (from your `general.yml` file). A common problem is - for the user that the MTA runs as not to have write access to - `files/raw_emails/`. + `CONTACT_EMAIL` (from your `general.yml` file). A common problem + is when the user that the MTA runs as does not have write access + to `files/raw_emails/`. * **Various tests fail with "*Your PostgreSQL connection does not support unescape_bytea. Try upgrading to pg 0.9.0 or later.*"** diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake index c54d981e2..1eee74aee 100644 --- a/lib/tasks/rspec.rake +++ b/lib/tasks/rspec.rake @@ -1,6 +1,6 @@ rspec_gem_dir = nil -Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| - rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") +Dir["#{Rails.root}/vendor/gems/*"].each do |subdir| + rspec_gem_dir = subdir if subdir.gsub("#{Rails.root}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") end rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') @@ -46,7 +46,7 @@ end Rake.application.instance_variable_get('@tasks').delete('default') -spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop +spec_prereq = File.exist?(File.join(Rails.root, 'config', 'database.yml')) ? "db:test:prepare" : :noop task :noop do end @@ -59,18 +59,18 @@ task :cruise => ['spec'] desc "Run all specs in spec directory (excluding plugin specs)" Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] end namespace :spec do desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = lambda do - IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + IO.readlines("#{Rails.root}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten end end @@ -89,21 +89,21 @@ namespace :spec do [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| desc "Run the code examples in spec/#{sub}" Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] end end desc "Run the code examples in vendor/plugins (except RSpec's own)" Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") end namespace :plugins do desc "Runs the examples for rspec_on_rails" Spec::Rake::SpecTask.new(:rspec_on_rails) do |t| - t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""] t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb'] end end diff --git a/public/dispatch.fcgi b/public/dispatch.fcgi index 3169ba267..ad34d90e4 100755 --- a/public/dispatch.fcgi +++ b/public/dispatch.fcgi @@ -4,7 +4,7 @@ # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # -# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log +# By default, the FastCGI crash log is Rails.root/log/fastcgi.crash.log # and the GC period is nil (turned off). A reasonable number of requests # could range from 10-100 depending on the memory footprint of your app. # diff --git a/script/generate_pot.sh b/script/generate_pot.sh index f6c82dda7..c0540c3d9 100755 --- a/script/generate_pot.sh +++ b/script/generate_pot.sh @@ -10,8 +10,8 @@ git status | grep app.po | awk '{print $3}' | xargs git add git commit -m "Backup latest po files from Transifex" # now regenerate POT and PO files from Alaveteli source -rake gettext:store_model_attributes -rake gettext:findpot +bundle exec rake gettext:store_model_attributes +bundle exec rake gettext:findpot # upload the result to Transifex tx push -t diff --git a/script/handle-mail-replies b/script/handle-mail-replies index d6717bc58..cc7595bed 100755 --- a/script/handle-mail-replies +++ b/script/handle-mail-replies @@ -145,7 +145,7 @@ end def load_rails require File.join('config', 'boot') - require RAILS_ROOT + '/config/environment' + require Rails.root + '/config/environment' end def record_bounce(email_address, bounce_message) diff --git a/script/load-sample-data b/script/load-sample-data index e5f1be4cd..fc5cbeed1 100755 --- a/script/load-sample-data +++ b/script/load-sample-data @@ -5,8 +5,7 @@ # have a filesystem representation of their contents LOC=`dirname "$0"` - -rake --silent spec:db:fixtures:load +bundle exec rake --silent spec:db:fixtures:load "$LOC/runner" /dev/stdin <<END env = ENV["RAILS_ENV"] diff --git a/script/rails-post-deploy b/script/rails-post-deploy index 6e2c88d28..5b9bd8014 100755 --- a/script/rails-post-deploy +++ b/script/rails-post-deploy @@ -76,9 +76,9 @@ fi if [ "$OPTION_STAGING_SITE" = "0" ] then - bundle install --without development:test --deployment + bundle exec bundle install --without development:test --deployment --binstubs else - bundle install + bundle exec bundle install --binstubs fi if [ -n "$OPTION_THEME_URL" ] @@ -87,6 +87,6 @@ then fi # upgrade database -rake db:migrate #--trace +bundle exec rake db:migrate #--trace diff --git a/script/rebuild-xapian-index b/script/rebuild-xapian-index index 5986f5259..3012511de 100755 --- a/script/rebuild-xapian-index +++ b/script/rebuild-xapian-index @@ -1,4 +1,4 @@ #!/bin/bash cd `dirname $0` -rake --silent "$@" xapian:rebuild_index models="PublicBody User InfoRequestEvent" +bundle exec rake --silent "$@" xapian:rebuild_index models="PublicBody User InfoRequestEvent" diff --git a/script/spec b/script/spec index 46fdbe6e4..c967e2a83 100755 --- a/script/spec +++ b/script/spec @@ -6,5 +6,6 @@ else ENV["RAILS_ENV"] ||= 'test' require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) end +Rails.preinitialize # load bundler require 'spec/autorun' exit ::Spec::Runner::CommandLine.run diff --git a/script/spec-all-pairs b/script/spec-all-pairs index 5b6439a4e..6d7bb17c4 100755 --- a/script/spec-all-pairs +++ b/script/spec-all-pairs @@ -6,7 +6,7 @@ log_file=/dev/null test_pair () { - rake db:test:prepare > /dev/null 2>&1 + bundle exec rake db:test:prepare > /dev/null 2>&1 output=$(script/spec "$1" "$2" 2>&1) if [ $? -eq 0 ] then diff --git a/script/spec_server b/script/spec_server index 1e839355f..dfdf8ff6c 100755 --- a/script/spec_server +++ b/script/spec_server @@ -41,7 +41,7 @@ module Spec load File.dirname(__FILE__) + '/../spec/spec_helper.rb' if in_memory_database? - load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default + load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default ActiveRecord::Migrator.up('db/migrate') # use migrations end @@ -80,7 +80,7 @@ def daemonize(pid_file = nil) return yield if $DEBUG pid = Process.fork{ Process.setsid - Dir.chdir(RAILS_ROOT) + Dir.chdir(Rails.root) trap("SIGINT"){ exit! 0 } trap("SIGTERM"){ exit! 0 } trap("SIGHUP"){ restart_test_server } diff --git a/script/test-run b/script/test-run index 4c7a0e3ec..7810b57d5 100755 --- a/script/test-run +++ b/script/test-run @@ -1,5 +1,5 @@ #!/bin/bash cd ../ -rake spec +bundle exec rake spec diff --git a/script/update-xapian-index b/script/update-xapian-index index 6ece02de0..d470176a9 100755 --- a/script/update-xapian-index +++ b/script/update-xapian-index @@ -1,5 +1,5 @@ #!/bin/bash - -cd `dirname $0` -rake --silent xapian:update_index "$@" +export BUNDLE_GEMFILE=$(dirname "$0")/../Gemfile +cd "$(dirname "$0")" +bundle exec rake --silent xapian:update_index "$@" diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index 60ac6969d..c2d645fd2 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -24,13 +24,7 @@ describe AdminUserController, "when administering users" do post_redirect = PostRedirect.get_last_post_redirect response.should redirect_to(:controller => 'user', :action => 'confirm', :email_token => post_redirect.email_token) end - - it "logs in as another user when already logged in as an admin" do - session[:user_id] = users(:admin_user).id - get :login_as, :id => users(:bob_smith_user).id - post_redirect = PostRedirect.get_last_post_redirect - response.should redirect_to(:controller => 'user', :action => 'confirm', :email_token => post_redirect.email_token) - session[:user_id].should be_nil - end + + # See also "allows an admin to log in as another user" in spec/integration/admin_spec.rb end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f50158ff9..81c69db76 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -121,6 +121,7 @@ describe RequestController, "when showing one request" do before(:each) do load_raw_emails_data + FileUtils.rm_rf File.join(File.dirname(__FILE__), "../../cache/zips") end it "should be successful" do @@ -565,7 +566,7 @@ end # XXX do this for invalid ids # it "should render 404 file" do -# response.should render_template("#{RAILS_ROOT}/public/404.html") +# response.should render_template("#{Rails.root}/public/404.html") # response.headers["Status"].should == "404 Not Found" # end diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb new file mode 100644 index 000000000..caf741749 --- /dev/null +++ b/spec/integration/admin_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +require "base64" + +describe "When administering the site" do + it "allows an admin to log in as another user" do + # First log in as Joe Admin + admin_user = users(:admin_user) + admin_user.email_confirmed = true + admin_user.save! + post_via_redirect "/profile/sign_in", :user_signin => {:email => admin_user.email, :password => "jonespassword"} + response.should be_success + + # Now fetch the "log in as" link to log in as Bob + admin_username = MySociety::Config.get('ADMIN_USERNAME') + admin_password = MySociety::Config.get('ADMIN_PASSWORD') + get_via_redirect "/admin/user/login_as/#{users(:bob_smith_user).id}", nil, { + "Authorization" => "Basic " + Base64.encode64("#{admin_username}:#{admin_password}").strip + } + response.should be_success + session[:user_id].should == users(:bob_smith_user).id + end +end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index e30916dff..baa1e6186 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -169,6 +169,11 @@ describe PublicBody, " when saving" do @public_body.save! @public_body.first_letter.should == 'T' end + + it "should not throw an error if the name is unset at the time the short_name is set" do + @public_body.name = nil + @public_body.short_name = nil + end end describe PublicBody, "when searching" do diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb index 8ed83b31f..ad58ea565 100644 --- a/spec/script/handle-mail-replies_spec.rb +++ b/spec/script/handle-mail-replies_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require "external_command" def mail_reply_test(email_filename) - Dir.chdir RAILS_ROOT do + Dir.chdir Rails.root do xc = ExternalCommand.new("script/handle-mail-replies", "--test") xc.run(load_file_fixture(email_filename)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c00da48bc..99cf8a2c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,7 +43,7 @@ Spec::Runner.configure do |config| # # You can also declare which fixtures to use (for example fixtures for test/fixtures): # - # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + # config.fixture_path = Rails.root + '/spec/fixtures/' # # == Mock Framework # diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tmp/.gitkeep |