aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb4
-rw-r--r--app/models/info_request.rb2
-rw-r--r--app/models/user.rb2
-rw-r--r--config/environment.rb6
-rw-r--r--config/test.yml2
-rw-r--r--lib/configuration.rb12
-rw-r--r--spec/models/user_spec.rb98
7 files changed, 63 insertions, 63 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 3296db6b7..c732a4b32 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -44,7 +44,7 @@ class RequestController < ApplicationController
end
def show
- if !Configuration::varnish_host.nil?
+ if !Configuration::varnish_host.blank?
# If varnish is set up to accept PURGEs, then cache for a
# long time
long_cache
@@ -876,7 +876,7 @@ class RequestController < ApplicationController
Zip::ZipFile.open(file_path, Zip::ZipFile::CREATE) { |zipfile|
convert_command = Configuration::html_to_pdf_command
done = false
- if File.exists?(convert_command)
+ if !convert_command.blank? && File.exists?(convert_command)
url = "http://#{Configuration::domain}#{request_url(info_request)}?print_stylesheet=1"
tempfile = Tempfile.new('foihtml2pdf')
output = AlaveteliExternalCommand.run(convert_command, url, tempfile.path)
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 47424e573..89893a396 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1139,7 +1139,7 @@ public
before_save :purge_in_cache
def purge_in_cache
- if !Configuration::varnish_host.nil? && !self.id.nil?
+ if !Configuration::varnish_host.blank? && !self.id.nil?
# we only do this for existing info_requests (new ones have a nil id)
path = url_for(:controller => 'request', :action => 'show', :url_title => self.url_title, :only_path => true, :locale => :none)
req = PurgeRequest.find_by_url(path)
diff --git a/app/models/user.rb b/app/models/user.rb
index 4a68d60d1..70386f7e4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -286,7 +286,7 @@ class User < ActiveRecord::Base
return false if self.no_limit
# Has the user issued as many as MAX_REQUESTS_PER_USER_PER_DAY requests in the past 24 hours?
- return false if Configuration::max_requests_per_user_per_day.nil?
+ return false if Configuration::max_requests_per_user_per_day.blank?
recent_requests = InfoRequest.count(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id])
return (recent_requests >= Configuration::max_requests_per_user_per_day)
diff --git a/config/environment.rb b/config/environment.rb
index 8076464a5..12501eb89 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -150,5 +150,7 @@ require 'world_foi_websites.rb'
require 'alaveteli_external_command.rb'
require 'quiet_opener.rb'
-ExceptionNotification::Notifier.sender_address = Configuration::exception_notifications_from
-ExceptionNotification::Notifier.exception_recipients = Configuration::exception_notifications_to
+if !Configuration.exception_notifications_from.blank? && !Configuration.exception_notifications_to.blank?
+ ExceptionNotification::Notifier.sender_address = Configuration::exception_notifications_from
+ ExceptionNotification::Notifier.exception_recipients = Configuration::exception_notifications_to
+end
diff --git a/config/test.yml b/config/test.yml
index ef270dcf2..565a3c4ec 100644
--- a/config/test.yml
+++ b/config/test.yml
@@ -122,7 +122,5 @@ HTML_TO_PDF_COMMAND: /usr/local/bin/wkhtmltopdf-amd64
EXCEPTION_NOTIFICATIONS_FROM: do-not-reply-to-this-address@example.com
EXCEPTION_NOTIFICATIONS_TO:
-MAX_REQUESTS_PER_USER_PER_DAY: 2
-
VARNISH_HOST: varnish.localdomain
SKIP_ADMIN_AUTH: true
diff --git a/lib/configuration.rb b/lib/configuration.rb
index baec8b67a..2878ed3b5 100644
--- a/lib/configuration.rb
+++ b/lib/configuration.rb
@@ -17,19 +17,19 @@ module Configuration
:DEBUG_RECORD_MEMORY => false,
:DEFAULT_LOCALE => '',
:DOMAIN => 'localhost:3000',
- :EXCEPTION_NOTIFICATIONS_FROM => nil,
- :EXCEPTION_NOTIFICATIONS_TO => nil,
+ :EXCEPTION_NOTIFICATIONS_FROM => '',
+ :EXCEPTION_NOTIFICATIONS_TO => '',
:FORCE_REGISTRATION_ON_NEW_REQUEST => false,
:FORWARD_NONBOUNCE_RESPONSES_TO => 'user-support@localhost',
:FRONTPAGE_PUBLICBODY_EXAMPLES => '',
:GA_CODE => '',
:GAZE_URL => '',
- :HTML_TO_PDF_COMMAND => nil,
+ :HTML_TO_PDF_COMMAND => '',
:INCOMING_EMAIL_DOMAIN => 'localhost',
:INCOMING_EMAIL_PREFIX => '',
:INCOMING_EMAIL_SECRET => 'dummysecret',
:ISO_COUNTRY_CODE => 'GB',
- :MAX_REQUESTS_PER_USER_PER_DAY => nil,
+ :MAX_REQUESTS_PER_USER_PER_DAY => '',
:MTA_LOG_TYPE => 'exim',
:NEW_RESPONSE_REMINDER_AFTER_DAYS => [3, 10, 24],
:OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS => '',
@@ -49,9 +49,9 @@ module Configuration
:TRACK_SENDER_NAME => 'Alaveteli',
:TWITTER_USERNAME => '',
:USE_DEFAULT_BROWSER_LANGUAGE => true,
- :USE_GHOSTSCRIPT_COMPRESSION => nil,
+ :USE_GHOSTSCRIPT_COMPRESSION => false,
:UTILITY_SEARCH_PATH => ["/usr/bin", "/usr/local/bin"],
- :VARNISH_HOST => nil,
+ :VARNISH_HOST => '',
:WORKING_OR_CALENDAR_DAYS => 'working',
}
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 03b2f34f9..e31c3f1b5 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,42 +1,42 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe User, "making up the URL name" do
+describe User, "making up the URL name" do
before do
@user = User.new
end
- it 'should remove spaces, and make lower case' do
+ it 'should remove spaces, and make lower case' do
@user.name = 'Some Name'
@user.url_name.should == 'some_name'
end
- it 'should not allow a numeric name' do
+ it 'should not allow a numeric name' do
@user.name = '1234'
@user.url_name.should == 'user'
end
end
-describe User, "showing the name" do
+describe User, "showing the name" do
before do
@user = User.new
@user.name = 'Some Name '
end
- it 'should strip whitespace' do
+ it 'should strip whitespace' do
@user.name.should == 'Some Name'
end
- it 'should show if user has been banned' do
+ it 'should show if user has been banned' do
@user.ban_text = "Naughty user"
@user.name.should == 'Some Name (Account suspended)'
end
end
-
+
describe User, " when authenticating" do
before do
- @empty_user = User.new
+ @empty_user = User.new
@full_user = User.new
@full_user.name = "Sensible User"
@@ -71,7 +71,7 @@ end
describe User, " when saving" do
before do
- @user = User.new
+ @user = User.new
end
it "should not save without setting some parameters" do
@@ -80,7 +80,7 @@ describe User, " when saving" do
it "should not save with misformatted email" do
@user.name = "Mr. Silly"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "mousefooble"
@user.should have(1).error_on(:email)
end
@@ -88,58 +88,58 @@ describe User, " when saving" do
it "should not allow an email address as a name" do
@user.name = "silly@example.com"
@user.email = "silly@example.com"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.should have(1).error_on(:name)
end
it "should not save with no password" do
@user.name = "Mr. Silly"
- @user.password = ""
+ @user.password = ""
@user.email = "silly@localhost"
@user.should have(1).error_on(:hashed_password)
end
it "should save with reasonable name, password and email" do
@user.name = "Mr. Reasonable"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "reasonable@localhost"
@user.save!
end
it "should let you make two users with same name" do
@user.name = "Mr. Flobble"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "flobble@localhost"
@user.save!
- @user2 = User.new
+ @user2 = User.new
@user2.name = "Mr. Flobble"
- @user2.password = "insecurepassword"
+ @user2.password = "insecurepassword"
@user2.email = "flobble2@localhost"
@user2.save!
end
-
+
it 'should mark the model for reindexing in xapian if the no_xapian_reindex flag is set to false' do
@user.name = "Mr. First"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "reasonable@localhost"
@user.no_xapian_reindex = false
@user.should_receive(:xapian_mark_needs_index)
@user.save!
end
-
+
it 'should mark the model for reindexing in xapian if the no_xapian_reindex flag is not set' do
@user.name = "Mr. Second"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "reasonable@localhost"
@user.no_xapian_reindex = nil
@user.should_receive(:xapian_mark_needs_index)
@user.save!
end
-
- it 'should not mark the model for reindexing in xapian if the no_xapian_reindex flag is set' do
+
+ it 'should not mark the model for reindexing in xapian if the no_xapian_reindex flag is set' do
@user.name = "Mr. Third"
- @user.password = "insecurepassword"
+ @user.password = "insecurepassword"
@user.email = "reasonable@localhost"
@user.no_xapian_reindex = true
@user.should_not_receive(:xapian_mark_needs_index)
@@ -149,47 +149,47 @@ describe User, " when saving" do
end
-describe User, "when reindexing referencing models" do
+describe User, "when reindexing referencing models" do
- before do
+ before do
@request_event = safe_mock_model(InfoRequestEvent, :xapian_mark_needs_index => true)
@request = safe_mock_model(InfoRequest, :info_request_events => [@request_event])
@comment_event = safe_mock_model(InfoRequestEvent, :xapian_mark_needs_index => true)
@comment = safe_mock_model(Comment, :info_request_events => [@comment_event])
@user = User.new(:comments => [@comment], :info_requests => [@request])
end
-
- it 'should reindex events associated with that user\'s comments when URL changes' do
+
+ it 'should reindex events associated with that user\'s comments when URL changes' do
@user.stub!(:changes).and_return({'url_name' => 1})
@comment_event.should_receive(:xapian_mark_needs_index)
@user.reindex_referencing_models
end
-
- it 'should reindex events associated with that user\'s requests when URL changes' do
+
+ it 'should reindex events associated with that user\'s requests when URL changes' do
@user.stub!(:changes).and_return({'url_name' => 1})
@request_event.should_receive(:xapian_mark_needs_index)
@user.reindex_referencing_models
end
-
- describe 'when no_xapian_reindex is set' do
- before do
+
+ describe 'when no_xapian_reindex is set' do
+ before do
@user.no_xapian_reindex = true
end
-
- it 'should not reindex events associated with that user\'s comments when URL changes' do
+
+ it 'should not reindex events associated with that user\'s comments when URL changes' do
@user.stub!(:changes).and_return({'url_name' => 1})
@comment_event.should_not_receive(:xapian_mark_needs_index)
@user.reindex_referencing_models
end
-
- it 'should not reindex events associated with that user\'s requests when URL changes' do
+
+ it 'should not reindex events associated with that user\'s requests when URL changes' do
@user.stub!(:changes).and_return({'url_name' => 1})
@request_event.should_not_receive(:xapian_mark_needs_index)
@user.reindex_referencing_models
end
-
+
end
-
+
end
describe User, "when checking abilities" do
@@ -208,26 +208,26 @@ describe User, "when checking abilities" do
end
-describe User, 'when asked if a user owns every request' do
-
- before do
+describe User, 'when asked if a user owns every request' do
+
+ before do
@mock_user = mock_model(User)
end
-
- it 'should return false if no user is passed' do
+
+ it 'should return false if no user is passed' do
User.owns_every_request?(nil).should be_false
end
-
- it 'should return true if the user has "requires admin" power' do
+
+ it 'should return true if the user has "requires admin" power' do
@mock_user.stub!(:owns_every_request?).and_return true
User.owns_every_request?(@mock_user).should be_true
end
-
- it 'should return false if the user does not have "requires admin" power' do
+
+ it 'should return false if the user does not have "requires admin" power' do
@mock_user.stub!(:owns_every_request?).and_return false
User.owns_every_request?(@mock_user).should be_false
end
-
+
end
describe User, " when making name and email address" do
@@ -296,7 +296,7 @@ describe User, "when emails have bounced" do
it "should record bounces" do
User.record_bounce_for_email("bob@localhost", "The reason we think the email bounced (e.g. a bounce message)")
-
+
user = User.find_user_by_email("bob@localhost")
user.email_bounced_at.should_not be_nil
user.email_bounce_message.should == "The reason we think the email bounced (e.g. a bounce message)"