summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2018-02-21 01:09:59 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2018-03-28 13:55:46 +0200
commita4ea9a93db98461479dcb8e1d7b8425a77018f1e (patch)
treeb8eedf8ac0fc16dda986ccd03fb33d2beeb2a11a /spec
parent3c23cefae0a323887503101d3c227a914dd8f7c4 (diff)
downloadgitlab-ce-a4ea9a93db98461479dcb8e1d7b8425a77018f1e.tar.gz
Add ChroniDurationAttribute concern
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/chronic_duration_attribute_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/models/concerns/chronic_duration_attribute_spec.rb b/spec/models/concerns/chronic_duration_attribute_spec.rb
new file mode 100644
index 00000000000..1a352537aaf
--- /dev/null
+++ b/spec/models/concerns/chronic_duration_attribute_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+shared_examples 'ChronicDurationAttribute' do
+ describe 'dynamically defined methods' do
+ it { expect(subject.class).to be_public_method_defined(virtual_field) }
+ it { expect(subject.class).to be_public_method_defined("#{virtual_field}=") }
+
+ it 'parses chronic duration input' do
+ subject.send("#{virtual_field}=", "10m")
+
+ expect(subject.send(source_field)).to eq(600)
+ end
+
+ it 'outputs chronic duration formated value' do
+ subject.send("#{source_field}=", 120)
+
+ expect(subject.send(virtual_field)).to eq('2m')
+ end
+ end
+end
+
+describe 'ChronicDurationAttribute' do
+ let(:source_field) { :maximum_job_timeout }
+ let(:virtual_field) { :maximum_job_timeout_user_readable }
+ subject { Ci::Runner.new }
+
+ it_behaves_like 'ChronicDurationAttribute'
+end