diff options
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/related_assets_controller_test.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/test/controllers/related_assets_controller_test.rb b/test/controllers/related_assets_controller_test.rb index a3082c2..7f6d487 100644 --- a/test/controllers/related_assets_controller_test.rb +++ b/test/controllers/related_assets_controller_test.rb | |||
| @@ -11,7 +11,7 @@ class RelatedAssetsControllerTest < ActionController::TestCase | |||
| 11 | Asset.create!(:name => "biometrics-poster", :upload_content_type => "image/png") | 11 | Asset.create!(:name => "biometrics-poster", :upload_content_type => "image/png") |
| 12 | Asset.create!(:name => "chaostreff-flyer", :upload_content_type => "image/png") | 12 | Asset.create!(:name => "chaostreff-flyer", :upload_content_type => "image/png") |
| 13 | 13 | ||
| 14 | get :search, params: { :node_id => node.id, :q => "biometrics" } | 14 | get :search, params: { :node_id => node.id, :search_term => "biometrics" } |
| 15 | 15 | ||
| 16 | json = JSON.parse(response.body) | 16 | json = JSON.parse(response.body) |
| 17 | names = json.map { |a| a["name"] } | 17 | names = json.map { |a| a["name"] } |
| @@ -20,13 +20,19 @@ class RelatedAssetsControllerTest < ActionController::TestCase | |||
| 20 | assert_not_includes names, "chaostreff-flyer" | 20 | assert_not_includes names, "chaostreff-flyer" |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | test "search returns an empty list for a blank term" do | 23 | test "search with a blank term returns the most recently created assets" do |
| 24 | Asset.delete_all | ||
| 25 | RelatedAsset.delete_all | ||
| 24 | login_as :quentin | 26 | login_as :quentin |
| 25 | node = Node.root.children.create!(:slug => "related_assets_blank_search_test") | 27 | node = Node.root.children.create!(:slug => "related_assets_recent_test") |
| 26 | 28 | ||
| 27 | get :search, params: { :node_id => node.id, :q => "" } | 29 | Asset.create!(:name => "older-photo", :upload_content_type => "image/png", :created_at => 2.days.ago) |
| 30 | Asset.create!(:name => "newer-photo", :upload_content_type => "image/png", :created_at => 1.hour.ago) | ||
| 28 | 31 | ||
| 29 | assert_equal [], JSON.parse(response.body) | 32 | get :search, params: { :node_id => node.id, :search_term => "" } |
| 33 | |||
| 34 | json = JSON.parse(response.body) | ||
| 35 | assert_equal ["newer-photo", "older-photo"], json.map { |a| a["name"] } | ||
| 30 | end | 36 | end |
| 31 | 37 | ||
| 32 | test "create attaches an asset to the node's editable page" do | 38 | test "create attaches an asset to the node's editable page" do |
