test/controller_module_test.rb in rails3-jquery-autocomplete-0.2.2 vs test/controller_module_test.rb in rails3-jquery-autocomplete-0.2.3
- old
+ new
@@ -9,10 +9,13 @@
class Actor < ActiveRecord::Base
belongs_to :movie
end
class Movie < ActiveRecord::Base
+ def display_name
+ "Movie: #{name}"
+ end
end
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :movies do |t|
@@ -114,7 +117,21 @@
get :autocomplete_movie_name, :term => 'ph'
json_response = JSON.parse(@response.body)
assert_equal(json_response.length, 1)
assert_equal(json_response.first["label"], 'aLpHa')
+ end
+
+ def test_value_option
+ ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
+
+ @movie = Movie.create(:name => 'Alpha')
+
+ get :autocomplete_movie_name, :term => 'Al'
+
+ json_response = JSON.parse(@response.body)
+
+ assert_equal(@movie.display_name, json_response.first["label"])
+ assert_equal(@movie.display_name, json_response.first["value"])
+ assert_equal(@movie.id, json_response.first["id"])
end
end
\ No newline at end of file