summaryrefslogtreecommitdiff
path: root/spec/helpers/application_helper_spec.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-17 14:04:14 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-17 16:37:10 -0400
commit8c8cd8be43e1e50a3dd99d1e491cfcb4fb54f945 (patch)
tree995e73b558f148f33a7ef2a294ac2fdb6d024ae0 /spec/helpers/application_helper_spec.rb
parente12b643192a945f5ff40da3dd1883616ae04e8d9 (diff)
downloadgitlab-ce-8c8cd8be43e1e50a3dd99d1e491cfcb4fb54f945.tar.gz
Update time_ago_with_tooltip helper
Minor refactoring, add specs, changes arguments to use keywords.
Diffstat (limited to 'spec/helpers/application_helper_spec.rb')
-rw-r--r--spec/helpers/application_helper_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 47e10197f5c..34fe08f5545 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -240,6 +240,54 @@ describe ApplicationHelper do
end
end
+ describe 'time_ago_with_tooltip' do
+ def element(*arguments)
+ time = Time.parse('2015-07-02 08:00')
+ element = time_ago_with_tooltip(time, *arguments)
+
+ Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
+ end
+
+ it 'returns a time element' do
+ expect(element.name).to eq 'time'
+ end
+
+ it 'includes the date string' do
+ expect(element.text).to match %r{2015-07-02 \d{2}:\d{2}:\d{2}}
+ end
+
+ it 'has a datetime attribute' do
+ expect(element.attr('datetime')).to eq '2015-07-02T12:00:00Z'
+ end
+
+ it 'has a formatted title attribute' do
+ expect(element.attr('title')).to eq 'Jul 02, 2015 12:00pm'
+ end
+
+ it 'includes a default js-timeago class' do
+ expect(element.attr('class')).to eq 'time_ago js-timeago'
+ end
+
+ it 'accepts a custom html_class' do
+ expect(element(html_class: 'custom_class').attr('class')).to eq 'custom_class js-timeago'
+ end
+
+ it 'accepts a custom tooltip placement' do
+ expect(element(placement: 'bottom').attr('data-placement')).to eq 'bottom'
+ end
+
+ it 're-initializes timeago Javascript' do
+ el = element.next_element
+
+ expect(el.name).to eq 'script'
+ expect(el.text).to include "$('.js-timeago').timeago()"
+ end
+
+ it 'allows the script tag to be excluded' do
+ expect(element(skip_js: true)).not_to include 'script'
+ end
+ end
+
describe 'render_markup' do
let(:content) { 'Noël' }