ref: master
test/unit/search_helper_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
require_relative "../test_helper" class SearchHelperTest < ActiveSupport::TestCase include SearchHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::FormTagHelper should 'display search page title' do title = 'page_title' assert_equal search_page_title(title), '<h1>page_title</h1>' end should 'display search page title with category name' do title = 'page_title' category = mock category.stubs(:name).returns('category_name') assert_equal '<h1>page_title - <small>category_name</small></h1>', search_page_title(title, {:category => category}) end should 'display category context' do stubs(:params).returns({:action => 'action'}) category = mock category.stubs(:full_name).returns('category_full_name') expects('link_to').returns('link_to_result').once expects('content_tag').with('div', 'category_full_name, link_to_result', anything) category_context(category, {}) end should 'display results without map' do stubs(:params).returns({:display => ''}) expects('render').with({:partial => 'display_results'}).returns('render_return') expects('content_tag').with('div', 'render_return', :class => 'map-or-list-search-results list') display_results end should 'display results with map' do stubs(:params).returns({:display => 'map'}) @query = 'test' @searches = {:enterprises => {:results => [1,2]}} expects('render').with({:partial => 'google_maps'}).returns('render_return') expects('content_tag').with('div', 'render_return', :class => 'map-or-list-search-results map') display_results(@searches, :enterprises) end should 'return full city name with state' do state = mock state.stubs(:kind_of?).with(State).returns(true) state.stubs(:acronym).returns('CE') city = mock city.stubs(:parent).returns(state) city.stubs(:kind_of?).with(City).returns(true) city.stubs(:name).returns('Jijoca de Jericoacoara') assert_equal 'Jijoca de Jericoacoara, CE', city_with_state(city) end should 'not return city_with_state when city is nil' do assert_nil city_with_state nil end should 'not return city_with_state when parameter is not a City' do city = mock city.stubs(:kind_of?).with(City).returns(false) assert_nil city_with_state city end should 'return city name when parent is not defined' do city = mock city.stubs(:kind_of?).with(City).returns(true) city.stubs(:parent).returns(nil) city.stubs(:name).returns('Feliz Deserto') assert_equal 'Feliz Deserto', city_with_state(city) end should 'return city name when parent is not a State' do state = mock state.stubs(:kind_of?).with(State).returns(false) city = mock city.stubs(:kind_of?).with(City).returns(true) city.stubs(:parent).returns(state) city.stubs(:name).returns('Feliz Deserto') assert_equal 'Feliz Deserto', city_with_state(city) end should 'return city name when parent has no acronym' do state = mock state.stubs(:kind_of?).with(State).returns(true) state.stubs(:acronym).returns(nil) city = mock city.stubs(:kind_of?).with(City).returns(true) city.stubs(:parent).returns(state) city.stubs(:name).returns('Feliz Deserto') assert_equal 'Feliz Deserto', city_with_state(city) end should 'return asset class from string' do asset_names = ['events', 'articles', 'enterprises', 'people', 'communities'] asset_classes = [Event, Article, Enterprise, Person, Community] asset_names.each_index do |i| assert_equal asset_classes[i], asset_class(asset_names[i]) end end should 'return an empty string in assets_submenu for articles assets' do @templates = {} assert_equal '', assets_submenu(:articles) @templates = {:articles => nil} assert_equal '', assets_submenu(:articles) end should 'return an empty string in assets_submenu for people asset without template' do @templates = {:people => nil} assert_equal '', assets_submenu(:people) @templates = {:people => []} assert_equal '', assets_submenu(:people) end should 'return an empty string in assets_submenu for people asset with only one template' do t = fast_create(Person, :is_template => true) @templates = {:people => [t]} assert_equal '', assets_submenu(:people) end should 'return a select of templates for people asset with more then one template' do t1 = fast_create(Person, :is_template => true) t2 = fast_create(Person, :is_template => true) @templates = {:people => [t1,t2]} SearchHelperTest.any_instance.stubs(:params).returns({}) assert_match /select/, assets_submenu(:people) assert_match /#{t1.name}/, assets_submenu(:people) assert_match /#{t2.name}/, assets_submenu(:people) end should 'return an empty string in assets_submenu for communities asset without template' do @templates = {:communities => nil} assert_equal '', assets_submenu(:communities) @templates = {:communities => []} assert_equal '', assets_submenu(:communities) end should 'return an empty string in assets_submenu for communities asset with only one template' do t = fast_create(Community, :is_template => true) @templates = {:communities => [t]} assert_equal '', assets_submenu(:communities) end should 'return a select of templates for communities asset with more then one template' do t1 = fast_create(Community, :is_template => true) t2 = fast_create(Community, :is_template => true) @templates = {:communities => [t1,t2]} SearchHelperTest.any_instance.stubs(:params).returns({}) assert_match /select/, assets_submenu(:communities) assert_match /#{t1.name}/, assets_submenu(:communities) assert_match /#{t2.name}/, assets_submenu(:communities) end should 'return an empty string in assets_submenu for enterprises asset without template' do @templates = {:enterprises => nil} assert_equal '', assets_submenu(:enterprises) @templates = {:enterprises => []} assert_equal '', assets_submenu(:enterprises) end should 'return an empty string in assets_submenu for enterprises asset with only one template' do t = fast_create(Enterprise, :is_template => true) @templates = {:enterprises => [t]} assert_equal '', assets_submenu(:enterprises) end should 'return a select of templates for enterprises asset with more then one template' do t1 = fast_create(Enterprise, :is_template => true) t2 = fast_create(Enterprise, :is_template => true) @templates = {:enterprises => [t1,t2]} SearchHelperTest.any_instance.stubs(:params).returns({}) assert_match /select/, assets_submenu(:enterprises) assert_match /#{t1.name}/, assets_submenu(:enterprises) assert_match /#{t2.name}/, assets_submenu(:enterprises) end end |