Commit 01c0f48380f6b3e3aff4947641261ca86647f892
1 parent
26e347c9
Exists in
master
and in
29 other branches
adding some functional tests
also: * keep the tip about separate tags by comma * include the css in the header page to have cache (ActionItem3280)
Showing
5 changed files
with
21 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -7,7 +7,7 @@ class CmsController < MyProfileController |
7 | 7 | def search_tags |
8 | 8 | arg = params[:term].downcase |
9 | 9 | result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) |
10 | - render :text => prepare_to_token_input2(result).to_json | |
10 | + render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def self.protect_if(*args) | ... | ... |
app/helpers/article_helper.rb
... | ... | @@ -83,7 +83,7 @@ module ArticleHelper |
83 | 83 | array.map { |object| {:id => object.id, :name => object.name} } |
84 | 84 | end |
85 | 85 | |
86 | - def prepare_to_token_input2(array) | |
86 | + def prepare_to_token_input_by_label(array) | |
87 | 87 | array.map { |object| {:label => object.name, :value => object.name} } |
88 | 88 | end |
89 | 89 | ... | ... |
app/helpers/layout_helper.rb
... | ... | @@ -27,6 +27,7 @@ module LayoutHelper |
27 | 27 | 'thickbox', |
28 | 28 | 'lightbox', |
29 | 29 | 'colorbox', |
30 | + 'inputosaurus', | |
30 | 31 | pngfix_stylesheet_path, |
31 | 32 | ] + tokeninput_stylesheets |
32 | 33 | plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } | ... | ... |
app/views/cms/edit.html.erb
test/functional/cms_controller_test.rb
... | ... | @@ -1807,6 +1807,23 @@ class CmsControllerTest < ActionController::TestCase |
1807 | 1807 | assert_template 'cms/publish' |
1808 | 1808 | end |
1809 | 1809 | |
1810 | + should 'response of search_tags be json' do | |
1811 | + get :search_tags, :profile => profile.identifier, :term => 'linux' | |
1812 | + assert_equal 'application/json', @response.content_type | |
1813 | + end | |
1814 | + | |
1815 | + should 'return empty json if does not find tag' do | |
1816 | + get :search_tags, :profile => profile.identifier, :term => 'linux' | |
1817 | + assert_equal "[]", @response.body | |
1818 | + end | |
1819 | + | |
1820 | + should 'return tags found' do | |
1821 | + tag = mock; tag.stubs(:name).returns('linux') | |
1822 | + ActsAsTaggableOn::Tag.stubs(:find).returns([tag]) | |
1823 | + get :search_tags, :profile => profile.identifier, :term => 'linux' | |
1824 | + assert_equal '[{"label":"linux","value":"linux"}]', @response.body | |
1825 | + end | |
1826 | + | |
1810 | 1827 | protected |
1811 | 1828 | |
1812 | 1829 | # FIXME this is to avoid adding an extra dependency for a proper JSON parser. | ... | ... |