summaryrefslogtreecommitdiff
path: root/spec/helpers/ci
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/ci')
-rw-r--r--spec/helpers/ci/application_helper_spec.rb37
-rw-r--r--spec/helpers/ci/runners_helper_spec.rb18
-rw-r--r--spec/helpers/ci/user_helper_spec.rb49
-rw-r--r--spec/helpers/ci/user_sessions_helper_spec.rb69
4 files changed, 173 insertions, 0 deletions
diff --git a/spec/helpers/ci/application_helper_spec.rb b/spec/helpers/ci/application_helper_spec.rb
new file mode 100644
index 00000000000..478c0266770
--- /dev/null
+++ b/spec/helpers/ci/application_helper_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Ci::ApplicationHelper do
+ describe "#duration_in_words" do
+ it "returns minutes and seconds" do
+ intervals_in_words = {
+ 100 => "1 minute 40 seconds",
+ 121 => "2 minutes 1 second",
+ 3721 => "62 minutes 1 second",
+ 0 => "0 seconds"
+ }
+
+ intervals_in_words.each do |interval, expectation|
+ duration_in_words(Time.now + interval, Time.now).should == expectation
+ end
+ end
+
+ it "calculates interval from now if there is no finished_at" do
+ duration_in_words(nil, Time.now - 5).should == "5 seconds"
+ end
+ end
+
+ describe "#time_interval_in_words" do
+ it "returns minutes and seconds" do
+ intervals_in_words = {
+ 100 => "1 minute 40 seconds",
+ 121 => "2 minutes 1 second",
+ 3721 => "62 minutes 1 second",
+ 0 => "0 seconds"
+ }
+
+ intervals_in_words.each do |interval, expectation|
+ time_interval_in_words(interval).should == expectation
+ end
+ end
+ end
+end
diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb
new file mode 100644
index 00000000000..e7681df10bd
--- /dev/null
+++ b/spec/helpers/ci/runners_helper_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Ci::RunnersHelper do
+ it "returns - not contacted yet" do
+ runner = FactoryGirl.build :runner
+ runner_status_icon(runner).should include("not connected yet")
+ end
+
+ it "returns offline text" do
+ runner = FactoryGirl.build(:runner, contacted_at: 1.day.ago, active: true)
+ runner_status_icon(runner).should include("Runner is offline")
+ end
+
+ it "returns online text" do
+ runner = FactoryGirl.build(:runner, contacted_at: 1.hour.ago, active: true)
+ runner_status_icon(runner).should include("Runner is online")
+ end
+end
diff --git a/spec/helpers/ci/user_helper_spec.rb b/spec/helpers/ci/user_helper_spec.rb
new file mode 100644
index 00000000000..f95bfb355ed
--- /dev/null
+++ b/spec/helpers/ci/user_helper_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+describe Ci::UserHelper do
+ describe :user_avatar_url do
+ let (:user) { User.new({'avatar_url' => avatar_url}) }
+
+ context 'no avatar' do
+ let (:avatar_url) { nil }
+
+ it 'should return a generic avatar' do
+ user_avatar_url(user).should == 'ci/no_avatar.png'
+ end
+ end
+
+ context 'plain gravatar' do
+ let (:base_url) { 'http://www.gravatar.com/avatar/abcdefgh' }
+ let (:avatar_url) { "#{base_url}?s=40&d=mm" }
+
+ it 'should return gravatar with default size' do
+ user_avatar_url(user).should == "#{base_url}?s=40&d=identicon"
+ end
+
+ it 'should return gravatar with custom size' do
+ user_avatar_url(user, 120).should == "#{base_url}?s=120&d=identicon"
+ end
+ end
+
+ context 'secure gravatar' do
+ let (:base_url) { 'https://secure.gravatar.com/avatar/abcdefgh' }
+ let (:avatar_url) { "#{base_url}?s=40&d=mm" }
+
+ it 'should return gravatar with default size' do
+ user_avatar_url(user).should == "#{base_url}?s=40&d=identicon"
+ end
+
+ it 'should return gravatar with custom size' do
+ user_avatar_url(user, 120).should == "#{base_url}?s=120&d=identicon"
+ end
+ end
+
+ context 'custom avatar' do
+ let (:avatar_url) { 'http://example.local/avatar.png' }
+
+ it 'should return custom avatar' do
+ user_avatar_url(user).should == avatar_url
+ end
+ end
+ end
+end
diff --git a/spec/helpers/ci/user_sessions_helper_spec.rb b/spec/helpers/ci/user_sessions_helper_spec.rb
new file mode 100644
index 00000000000..5f654866d99
--- /dev/null
+++ b/spec/helpers/ci/user_sessions_helper_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe Ci::UserSessionsHelper do
+ describe :generate_oauth_hmac do
+ let (:salt) { 'a' }
+ let (:salt2) { 'b' }
+ let (:return_to) { 'b' }
+
+ it 'should return null if return_to is also null' do
+ generate_oauth_hmac(salt, nil).should be_nil
+ end
+
+ it 'should return not null if return_to is also not null' do
+ generate_oauth_hmac(salt, return_to).should_not be_nil
+ end
+
+ it 'should return different hmacs for different salts' do
+ secret1 = generate_oauth_hmac(salt, return_to)
+ secret2 = generate_oauth_hmac(salt2, return_to)
+ secret1.should_not eq(secret2)
+ end
+ end
+
+ describe :generate_oauth_state do
+ let (:return_to) { 'b' }
+
+ it 'should return null if return_to is also null' do
+ generate_oauth_state(nil).should be_nil
+ end
+
+ it 'should return two different states for same return_to' do
+ state1 = generate_oauth_state(return_to)
+ state2 = generate_oauth_state(return_to)
+ state1.should_not eq(state2)
+ end
+ end
+
+ describe :get_ouath_state_return_to do
+ let (:return_to) { 'a' }
+ let (:state) { generate_oauth_state(return_to) }
+
+ it 'should return return_to' do
+ get_ouath_state_return_to(state).should eq(return_to)
+ end
+ end
+
+ describe :is_oauth_state_valid? do
+ let (:return_to) { 'a' }
+ let (:state) { generate_oauth_state(return_to) }
+ let (:forged) { "forged#{state}" }
+ let (:invalid) { 'aa' }
+ let (:invalid2) { 'aa:bb' }
+ let (:invalid3) { 'aa:bb:' }
+
+ it 'should validate oauth state' do
+ is_oauth_state_valid?(state).should be_true
+ end
+
+ it 'should not validate forged state' do
+ is_oauth_state_valid?(forged).should be_false
+ end
+
+ it 'should not validate invalid state' do
+ is_oauth_state_valid?(invalid).should be_false
+ is_oauth_state_valid?(invalid2).should be_false
+ is_oauth_state_valid?(invalid3).should be_false
+ end
+ end
+end