Commit 01c0f48380f6b3e3aff4947641261ca86647f892

Authored by Joenio Costa
1 parent 26e347c9

adding some functional tests

also:
* keep the tip about separate tags by comma
* include the css in the header page to have cache

(ActionItem3280)
app/controllers/my_profile/cms_controller.rb
@@ -7,7 +7,7 @@ class CmsController < MyProfileController @@ -7,7 +7,7 @@ class CmsController < MyProfileController
7 def search_tags 7 def search_tags
8 arg = params[:term].downcase 8 arg = params[:term].downcase
9 result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) 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 end 11 end
12 12
13 def self.protect_if(*args) 13 def self.protect_if(*args)
app/helpers/article_helper.rb
@@ -83,7 +83,7 @@ module ArticleHelper @@ -83,7 +83,7 @@ module ArticleHelper
83 array.map { |object| {:id => object.id, :name => object.name} } 83 array.map { |object| {:id => object.id, :name => object.name} }
84 end 84 end
85 85
86 - def prepare_to_token_input2(array) 86 + def prepare_to_token_input_by_label(array)
87 array.map { |object| {:label => object.name, :value => object.name} } 87 array.map { |object| {:label => object.name, :value => object.name} }
88 end 88 end
89 89
app/helpers/layout_helper.rb
@@ -27,6 +27,7 @@ module LayoutHelper @@ -27,6 +27,7 @@ module LayoutHelper
27 'thickbox', 27 'thickbox',
28 'lightbox', 28 'lightbox',
29 'colorbox', 29 'colorbox',
  30 + 'inputosaurus',
30 pngfix_stylesheet_path, 31 pngfix_stylesheet_path,
31 ] + tokeninput_stylesheets 32 ] + tokeninput_stylesheets
32 plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } 33 plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') }
app/views/cms/edit.html.erb
@@ -33,9 +33,8 @@ @@ -33,9 +33,8 @@
33 33
34 <br /> 34 <br />
35 35
36 - <%= stylesheet_link_tag('inputosaurus') %>  
37 -  
38 <%= f.text_field('tag_list', :size => 64) %> 36 <%= f.text_field('tag_list', :size => 64) %>
  37 + <%= content_tag( 'small', _('Separate tags with commas') ) %>
39 38
40 <script> 39 <script>
41 jQuery('#article_tag_list').inputosaurus({ 40 jQuery('#article_tag_list').inputosaurus({
test/functional/cms_controller_test.rb
@@ -1807,6 +1807,23 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1807,6 +1807,23 @@ class CmsControllerTest &lt; ActionController::TestCase
1807 assert_template 'cms/publish' 1807 assert_template 'cms/publish'
1808 end 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 protected 1827 protected
1811 1828
1812 # FIXME this is to avoid adding an extra dependency for a proper JSON parser. 1829 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.