Skip to content

Commit

Permalink
Added tests for sorting nodes on tag page by likes and views DESC (#5138
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alonpeer authored and jywarren committed Mar 18, 2019
1 parent e27121f commit 64d805c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
11 changes: 7 additions & 4 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ post_test1:
changed: <%= DateTime.new(2018,8,1).to_i %>
status: 1
type: "note"
cached_likes: 0
cached_likes: 8
views: 6
longitude: 52.0
latitude: 160.0
precision: 1
Expand All @@ -289,7 +290,8 @@ post_test2:
changed: <%= DateTime.new(2018,8,8).to_i %>
status: 1
type: "note"
cached_likes: 0
cached_likes: 3
views: 3
longitude: 52.23
latitude: 34.57
precision: 2
Expand All @@ -304,7 +306,8 @@ post_test3:
changed: <%= DateTime.new(2018,8,15).to_i %>
status: 1
type: "note"
cached_likes: 0
cached_likes: 7
views: 9
longitude: 52.0
latitude: 12.0
precision: 1
Expand Down Expand Up @@ -380,4 +383,4 @@ purple_air_with_hyphen:
status: 1
type: "note"
cached_likes: 0
slug: "purple-air-with-hyphen"
slug: "purple-air-with-hyphen"
27 changes: 20 additions & 7 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup
UserSession.create(users(:bob))

post :create,
params: {
params: {
name: 'my invalid tag $_',
nid: nodes(:one).nid
}
Expand All @@ -76,7 +76,7 @@ def setup
UserSession.create(users(:bob))

post :create,
params: {
params: {
name: 'with:bob',
nid: nodes(:one).nid # authored by jeff, not bob
}
Expand Down Expand Up @@ -170,12 +170,26 @@ def setup
# assert_equal assigns['tags'].length, 1
assert_select '#wiki-content', 1
end

test 'show page for non-existent tag' do
get :show, params: { id: 'nonexistent' }
assert :success
end

test 'tag show, sort by views DESC' do
get :show, params: { id: tags(:latitude).name, order: 'views' }
views_array = assigns['notes'].map(&:views)
sorted_views_array = views_array.sort.reverse
assert_equal sorted_views_array, views_array
end

test 'tag show, sort by likes DESC' do
get :show, params: { id: tags(:latitude).name, order: 'likes' }
likes_array = assigns['notes'].map(&:cached_likes)
sorted_likes_array = likes_array.sort.reverse
assert_equal sorted_likes_array, likes_array
end

test 'tag show range' do
get :show, params: { id: tags(:spectrometer).name,
start: (Time.now - 1.day).strftime('%d-%m-%Y'),
Expand Down Expand Up @@ -334,7 +348,7 @@ def setup

test 'tag contributors' do
get :show,
params: {
params: {
node_type: 'contributors',
id: Tag.last.name
}
Expand Down Expand Up @@ -618,14 +632,14 @@ def setup
end
assert_not ActionMailer::Base.deliveries.collect(&:subject).include?("#{node.title} (#{tagname})")
end

test 'should render a text/pain when a tag is deleted through post request xhr' do
user = UserSession.create(users(:jeff))
node_tag = node_tags(:awesome)
post :delete, params: { nid: node_tag.nid, tid: node_tag.tid, uid: node_tag.uid}, xhr: true
assert_equal "#{node_tag.tid}", @response.body
end

test 'add_parent method adds a tag parent' do
user = UserSession.create(users(:admin))
get :add_parent, params: { name: Tag.last.name, parent: Tag.first.name }
Expand Down Expand Up @@ -672,4 +686,3 @@ def setup
assert_response :success
end
end

0 comments on commit 64d805c

Please sign in to comment.