Skip to content

Commit

Permalink
Merge pull request #80 from ElsonOtake/analytics
Browse files Browse the repository at this point in the history
New integration test
  • Loading branch information
ElsonOtake authored Dec 1, 2023
2 parents 7beff51 + b6a91fc commit ec58d13
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
## 🚀 Live Demo <a name="live-demo"></a>

- [Render](https://elsonotake-blog.onrender.com/)
- [Heroku](https://radiant-savannah-10557-415f690b4dd7.herokuapp.com/)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down
65 changes: 65 additions & 0 deletions test/integration/analytics_render_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'test_helper'

#
# Test analytics integration without using background jobs (CreateCounterJob, CreateLengthJob,
# CreateBrowserJob, and CreateUniqueJob) in app/controllers/concerns/track_event.rb.
#
# My Render account does not allow me to run Sidekiq on deployments.
#

class AnalyticsRenderIntegrationTest < ActionDispatch::IntegrationTest
setup do
@member = Member.first
@post = Post.first
@comment = Comment.first
end

test 'should redirect from root page if user not signed in' do
get root_url
assert_response :redirect
end

test 'should get root page if user signed in' do
sign_in @member
get root_url
assert_response :success
end

test 'should not create analytic data on new posts' do
sign_in @member
get "/members/#{@member.id}/posts/new"
assert_response :success
post "/members/#{@member.id}/posts",
params: { post: { title: 'MyString', text: 'MyString', author: @member } }
assert_response :redirect
follow_redirect!
assert_response :success
end

test 'should create analytic data on creating comments' do
sign_in @member
get "/members/#{@member.id}/posts/#{@post.id}/comments/new"
assert_response :success
post "/members/#{@member.id}/posts/#{@post.id}/comments",
params: { comment: { text: 'MyString', author: @member, post: @post } }
assert_response :redirect
follow_redirect!
assert_response :success
end

test 'should create analytic data on updating comments' do
sign_in @member
get "/members/#{@member.id}/posts/#{@post.id}/comments/#{@comment.id}/edit"
assert_response :success
put "/members/#{@member.id}/posts/#{@post.id}/comments/#{@comment.id}",
params: { comment: { text: 'MyString', author: @member, post: @post } }
assert_response :redirect
end

test 'should create analytic data on deleting comments' do
sign_in @member
delete "/members/#{@member.id}/posts/#{@post.id}/comments/#{@comment.id}",
params: { comment: { member: @member, post: @post, id: @comment.id } }
assert_response :redirect
end
end
5 changes: 5 additions & 0 deletions test/integration/analytics_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'test_helper'
require 'sidekiq/testing'

#
# Test analytics integration using background jobs (CreateCounterJob, CreateLengthJob,
# CreateBrowserJob, and CreateUniqueJob) in app/controllers/concerns/track_event.rb.
#

class AnalyticsIntegrationTest < ActionDispatch::IntegrationTest
setup do
# A test fake that pushes all jobs into a jobs array
Expand Down

0 comments on commit ec58d13

Please sign in to comment.