aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/comment_controller_spec.rb32
-rw-r--r--spec/helpers/link_to_helper_spec.rb40
-rw-r--r--spec/lib/alaveteli_external_command_spec.rb (renamed from spec/lib/alaveteli_external_command.rb)0
-rw-r--r--spec/lib/basic_encoding_spec.rb (renamed from spec/lib/basic_encoding_tests.rb)20
-rw-r--r--spec/lib/confidence_intervals_spec.rb (renamed from spec/lib/confidence_intervals.rb)0
-rw-r--r--spec/lib/i18n_interpolation_spec.rb (renamed from spec/lib/i18n_interpolation.rb)1
-rw-r--r--spec/mailers/info_request_batch_mailer_spec.rb (renamed from spec/mailers/info_request_batch_mailer.rb)0
7 files changed, 72 insertions, 21 deletions
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
index c03615ce2..5e250f689 100644
--- a/spec/controllers/comment_controller_spec.rb
+++ b/spec/controllers/comment_controller_spec.rb
@@ -53,16 +53,30 @@ describe CommentController, "when commenting on a request" do
response.should render_template('new')
end
-
+
it "should not allow comments if comments are not allowed" do
- session[:user_id] = users(:silly_name_user).id
-
- expect {
- post :new, :url_title => info_requests(:spam_1_request).url_title,
- :comment => { :body => "I demand to be heard!" },
- :type => 'request', :submitted_comment => 1, :preview => 0
- }.to raise_error("Comments are not allowed on this request")
-
+ session[:user_id] = users(:silly_name_user).id
+ info_request = info_requests(:spam_1_request)
+
+ post :new, :url_title => info_request.url_title,
+ :comment => { :body => "I demand to be heard!" },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ response.should redirect_to(show_request_path(info_request.url_title))
+ flash[:notice].should == 'Comments are not allowed on this request'
+ end
+
+ it "should not allow comments from banned users" do
+ User.any_instance.stub(:ban_text).and_return('Banned from commenting')
+
+ user = users(:silly_name_user)
+ session[:user_id] = user.id
+
+ post :new, :url_title => info_requests(:fancy_dog_request).url_title,
+ :comment => { :body => comments(:silly_comment).body },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ response.should render_template('user/banned')
end
describe 'when commenting on an external request' do
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index 2259db6c2..4a01ec683 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -70,14 +70,50 @@ describe LinkToHelper do
end
describe 'simple_date' do
+
+ it 'formats a date in html by default' do
+ time = Time.utc(2012, 11, 07, 21, 30, 26)
+ self.should_receive(:simple_date_html).with(time)
+ simple_date(time)
+ end
+
+ it 'formats a date in the specified format' do
+ time = Time.utc(2012, 11, 07, 21, 30, 26)
+ self.should_receive(:simple_date_text).with(time)
+ simple_date(time, :format => :text)
+ end
+
+ it 'raises an argument error if given an unrecognized format' do
+ time = Time.utc(2012, 11, 07, 21, 30, 26)
+ expect { simple_date(time, :format => :unknown) }.to raise_error(ArgumentError)
+ end
+
+ end
+
+ describe 'simple_date_html' do
+
+ it 'formats a date in a time tag' do
+ Time.use_zone('London') do
+ time = Time.utc(2012, 11, 07, 21, 30, 26)
+ expected = "<time datetime=\"2012-11-07T21:30:26+00:00\" title=\"2012-11-07 21:30:26 +0000\">November 07, 2012</time>"
+ simple_date_html(time).should == expected
+ end
+ end
+
+ end
+
+ describe 'simple_date_text' do
+
it 'should respect time zones' do
Time.use_zone('Australia/Sydney') do
- simple_date(Time.utc(2012, 11, 07, 21, 30, 26)).should == 'November 08, 2012'
+ simple_date_text(Time.utc(2012, 11, 07, 21, 30, 26)).should == 'November 08, 2012'
end
end
it 'should handle Date objects' do
- simple_date(Date.new(2012, 11, 21)).should == 'November 21, 2012'
+ simple_date_text(Date.new(2012, 11, 21)).should == 'November 21, 2012'
end
+
end
+
end
diff --git a/spec/lib/alaveteli_external_command.rb b/spec/lib/alaveteli_external_command_spec.rb
index 18afeda33..18afeda33 100644
--- a/spec/lib/alaveteli_external_command.rb
+++ b/spec/lib/alaveteli_external_command_spec.rb
diff --git a/spec/lib/basic_encoding_tests.rb b/spec/lib/basic_encoding_spec.rb
index 35d35fd4a..43a65eab9 100644
--- a/spec/lib/basic_encoding_tests.rb
+++ b/spec/lib/basic_encoding_spec.rb
@@ -4,8 +4,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
def bytes_to_binary_string( bytes, claimed_encoding = nil )
claimed_encoding ||= 'ASCII-8BIT'
bytes_string = bytes.pack('c*')
- if RUBY_VERSION.to_f >= 1.9
- bytes_string.force_encoding! claimed_encoding
+ if String.method_defined?(:force_encoding)
+ bytes_string.force_encoding claimed_encoding
end
bytes_string
end
@@ -110,15 +110,15 @@ describe "convert_string_to_utf8_or_binary" do
converted = convert_string_to_utf8_or_binary random_string
converted.should == random_string
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'ASCII-8BIT'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'ASCII-8BIT'
end
converted = convert_string_to_utf8_or_binary random_string,'UTF-8'
converted.should == random_string
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'ASCII-8BIT'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'ASCII-8BIT'
end
end
@@ -132,8 +132,8 @@ describe "convert_string_to_utf8_or_binary" do
converted.should == "DASH – DASH"
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'UTF-8'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
end
end
@@ -147,8 +147,8 @@ describe "convert_string_to_utf8_or_binary" do
converted.should start_with("贵公司负责人")
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'UTF-8'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
end
end
diff --git a/spec/lib/confidence_intervals.rb b/spec/lib/confidence_intervals_spec.rb
index cb8717f3d..cb8717f3d 100644
--- a/spec/lib/confidence_intervals.rb
+++ b/spec/lib/confidence_intervals_spec.rb
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation_spec.rb
index b07cf1e9a..47037ecdb 100644
--- a/spec/lib/i18n_interpolation.rb
+++ b/spec/lib/i18n_interpolation_spec.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "when using i18n" do
diff --git a/spec/mailers/info_request_batch_mailer.rb b/spec/mailers/info_request_batch_mailer_spec.rb
index 19791e163..19791e163 100644
--- a/spec/mailers/info_request_batch_mailer.rb
+++ b/spec/mailers/info_request_batch_mailer_spec.rb