application_helper_spec.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. require 'spec_helper'
  2. describe ApplicationHelper do
  3. describe '#nav_link' do
  4. it 'returns a nav link' do
  5. stub(self).current_page?('/things') { false }
  6. nav = nav_link('Things', '/things')
  7. a = Nokogiri(nav).at('li:not(.active) > a[href="/things"]')
  8. expect(a.text.strip).to eq('Things')
  9. end
  10. it 'returns a nav link with a glyphicon' do
  11. stub(self).current_page?('/things') { false }
  12. nav = nav_link('Things', '/things', glyphicon: 'help')
  13. expect(nav).to be_html_safe
  14. a = Nokogiri(nav).at('li:not(.active) > a[href="/things"]')
  15. expect(a.at('span.glyphicon.glyphicon-help')).to be_a Nokogiri::XML::Element
  16. expect(a.text.strip).to eq('Things')
  17. end
  18. it 'returns an active nav link' do
  19. stub(self).current_page?('/things') { true }
  20. nav = nav_link('Things', '/things')
  21. expect(nav).to be_html_safe
  22. a = Nokogiri(nav).at('li.active > a[href="/things"]')
  23. expect(a).to be_a Nokogiri::XML::Element
  24. expect(a.text.strip).to eq('Things')
  25. end
  26. describe 'with block' do
  27. it 'returns a nav link with menu' do
  28. stub(self).current_page?('/things') { false }
  29. stub(self).current_page?('/things/stuff') { false }
  30. nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
  31. expect(nav).to be_html_safe
  32. a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > a[href="/things"]')
  33. expect(a0).to be_a Nokogiri::XML::Element
  34. expect(a0.text.strip).to eq('Things')
  35. a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > li:not(.active) > a[href="/things/stuff"]')
  36. expect(a1).to be_a Nokogiri::XML::Element
  37. expect(a1.text.strip).to eq('Stuff')
  38. end
  39. it 'returns an active nav link with menu' do
  40. stub(self).current_page?('/things') { true }
  41. stub(self).current_page?('/things/stuff') { false }
  42. nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
  43. expect(nav).to be_html_safe
  44. a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
  45. expect(a0).to be_a Nokogiri::XML::Element
  46. expect(a0.text.strip).to eq('Things')
  47. a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
  48. expect(a1).to be_a Nokogiri::XML::Element
  49. expect(a1.text.strip).to eq('Stuff')
  50. end
  51. it 'returns an active nav link with menu when on a child page' do
  52. stub(self).current_page?('/things') { false }
  53. stub(self).current_page?('/things/stuff') { true }
  54. nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
  55. expect(nav).to be_html_safe
  56. a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
  57. expect(a0).to be_a Nokogiri::XML::Element
  58. expect(a0.text.strip).to eq('Things')
  59. a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
  60. expect(a1).to be_a Nokogiri::XML::Element
  61. expect(a1.text.strip).to eq('Stuff')
  62. end
  63. end
  64. end
  65. describe '#yes_no' do
  66. it 'returns a label "Yes" if any truthy value is given' do
  67. [true, Object.new].each { |value|
  68. label = yes_no(value)
  69. expect(label).to be_html_safe
  70. expect(Nokogiri(label).text).to eq 'Yes'
  71. }
  72. end
  73. it 'returns a label "No" if any falsy value is given' do
  74. [false, nil].each { |value|
  75. label = yes_no(value)
  76. expect(label).to be_html_safe
  77. expect(Nokogiri(label).text).to eq 'No'
  78. }
  79. end
  80. end
  81. describe '#working' do
  82. before do
  83. @agent = agents(:jane_website_agent)
  84. end
  85. it 'returns a label "Disabled" if a given agent is disabled' do
  86. stub(@agent).disabled? { true }
  87. label = working(@agent)
  88. expect(label).to be_html_safe
  89. expect(Nokogiri(label).text).to eq 'Disabled'
  90. end
  91. it 'returns a label "Missing Gems" if a given agent has dependencies missing' do
  92. stub(@agent).dependencies_missing? { true }
  93. label = working(@agent)
  94. expect(label).to be_html_safe
  95. expect(Nokogiri(label).text).to eq 'Missing Gems'
  96. end
  97. it 'returns a label "Yes" if a given agent is working' do
  98. stub(@agent).working? { true }
  99. label = working(@agent)
  100. expect(label).to be_html_safe
  101. expect(Nokogiri(label).text).to eq 'Yes'
  102. end
  103. it 'returns a label "No" if a given agent is not working' do
  104. stub(@agent).working? { false }
  105. label = working(@agent)
  106. expect(label).to be_html_safe
  107. expect(Nokogiri(label).text).to eq 'No'
  108. end
  109. end
  110. describe '#icon_for_service' do
  111. it 'returns a correct icon tag for Twitter' do
  112. icon = icon_for_service(:twitter)
  113. expect(icon).to be_html_safe
  114. elem = Nokogiri(icon).at('i.fa.fa-twitter')
  115. expect(elem).to be_a Nokogiri::XML::Element
  116. end
  117. it 'returns a correct icon tag for GitHub' do
  118. icon = icon_for_service(:github)
  119. expect(icon).to be_html_safe
  120. elem = Nokogiri(icon).at('i.fa.fa-github')
  121. expect(elem).to be_a Nokogiri::XML::Element
  122. end
  123. it 'returns a correct icon tag for other services' do
  124. icon = icon_for_service(:'37signals')
  125. expect(icon).to be_html_safe
  126. elem = Nokogiri(icon).at('i.fa.fa-lock')
  127. expect(elem).to be_a Nokogiri::XML::Element
  128. end
  129. end
  130. end