Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for controllers #615

Merged
merged 19 commits into from
Jun 3, 2019
Merged

Add tests for controllers #615

merged 19 commits into from
Jun 3, 2019

Conversation

kaustubh-nair
Copy link
Member

Part of #594

test/functional/utility_controller_test.rb Outdated Show resolved Hide resolved
test/functional/utility_controller_test.rb Outdated Show resolved Hide resolved
test/functional/utility_controller_test.rb Outdated Show resolved Hide resolved
test/functional/utility_controller_test.rb Outdated Show resolved Hide resolved
test/functional/utility_controller_test.rb Outdated Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented May 16, 2019

Code Climate has analyzed commit c5c5524 and detected 40 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 40

View more on Code Climate.

@codecov
Copy link

codecov bot commented May 16, 2019

Codecov Report

Merging #615 into main will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #615   +/-   ##
=====================================
  Coverage   41.1%   41.1%           
=====================================
  Files         34      34           
  Lines       1321    1321           
=====================================
  Hits         543     543           
  Misses       778     778
Impacted Files Coverage Δ
app/models/export.rb 27.77% <ø> (ø) ⬆️

@kaustubh-nair
Copy link
Member Author

The sessions controller is the only major controller that needs more coverage. But I'm not really sure how it works
Can anyone help out with that?

@kaustubh-nair

This comment has been minimized.

@kaustubh-nair

This comment has been minimized.

@kaustubh-nair
Copy link
Member Author

@publiclab/reviewers This is ready for merge.
sessions_controller is the only one having low coverage.
Can anyone give a rough outline of how the current authentication system works? I can then write tests for that as well.
Thanks

@@ -40,7 +40,7 @@ def self.histogram_cm_per_pixel

def self.histogram_cm_per_pixel_in_tens
e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500')
.order(cm_per_pixel: 'desc')
.order('cm_per_pixel desc')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer cm_per_pixel: :desc because it is rails way.
Would love to hear from you 😄 .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is related to our MySQL adapter gem version.

test/functional/sessions_controller_test.rb Outdated Show resolved Hide resolved
@jywarren
Copy link
Member

Hi! Sorry I missed this! Can you resolve conflicts, and could we get a review from someone else in @publiclab/mapknitter-reviewers as well? Thanks so much, this is great!

Regarding sessions, perhaps we could ask @SidharthBansal to offer input on how we might test those?

@alaxalves
Copy link
Member

Is this ready to merge? @kaustubh-nair

@kaustubh-nair
Copy link
Member Author

Is this ready to merge? @kaustubh-nair

Yes it is. Can you review it if you have time?

.rubocop.yml Outdated
@@ -0,0 +1,10 @@
Metrics/BlockLength:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is not needed since #547 is ready to merge too. And we're using our standard stylesheet.

# assert_includes @response.body, @annotation.text
# end

test 'should update annotations' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be blank?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update and destroy actions don't work
So i left them blank for now.

test 'should update annotations' do
end

test 'should destroy annotations' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be blank?

def setup
@map = maps(:saugus)
end

def teardown
end

test "index" do
test 'index' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more significant and standardized test names would be bettter, such as test 'should visit Export index page'

end

test "cancel fails if not logged in" do
test 'cancel fails if not logged in' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert assigns[:map]
assert_equal 'text/html', @response.content_type
assert flash.empty?
end

test "cancels export" do
test 'cancels export' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session[:user_id] = 1
get :cancel, id: @map.id
assert_response :success
assert_equal 'cancelled', @response.body
assert assigns[:map]
end

test "exports cancelled if present" do
test 'exports cancelled if present' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session[:user_id] = 1
get :cancel, id: @map.id, exports: 'cess'
assert_response :redirect
assert flash.present?
assert_redirected_to '/exports'
end

test "progress" do
test 'progress' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get :progress, id: @map.id
assert_response :success
assert_equal 'export not running', @response.body
assert_equal 'text/html', @response.content_type
end

test 'progress with no export' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_equal 'export has not been run', @response.body
end

test 'progress completed' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_equal 'complete', @response.body
end

test 'progress failed' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -25,100 +24,100 @@ def teardown
assert_equal image_urls, json_response[0]['image_urls']
end

test "should get index" do
test 'should get index' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require 'test_helper'

class UtilityControllerTest < ActionController::TestCase
test 'tms_alt' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alaxalves
Copy link
Member

Is this ready to merge? @kaustubh-nair

Yes it is. Can you review it if you have time?

Just did that @kaustubh-nair. Check out my comments, despite of those test names I think everything is ok.

@jywarren
Copy link
Member

OK! Just ping me (preferably in Gitter actually as I'm working offline a lot today) and we can merge this!

@alaxalves alaxalves mentioned this pull request May 31, 2019
5 tasks
@kaustubh-nair
Copy link
Member Author

Okay!
@alaxalves this is ready

@alaxalves alaxalves force-pushed the controller-tests branch 3 times, most recently from 1402a9e to 09d64d9 Compare June 2, 2019 18:41
@jywarren
Copy link
Member

jywarren commented Jun 3, 2019

All ready for a merge here now? Just checking since I saw a few more commits come in!

@jywarren
Copy link
Member

jywarren commented Jun 3, 2019

Feel free to label it ready so I know for sure, and take the label off again if it needs a bit more time!

@kaustubh-nair
Copy link
Member Author

Yes @jywarren this is ready 👍

@jywarren jywarren merged commit 62eec1e into main Jun 3, 2019
@jywarren
Copy link
Member

jywarren commented Jun 3, 2019

Super!!!

chen-robert pushed a commit to chen-robert/mapknitter that referenced this pull request Dec 5, 2019
* add utility test

* Add exports and annotations controller tests'

* Add tests for images

* Fix codeclimate issues

* Single quoted strings, huh :/

* Fix export controller test

* Fix histogram ordering

* Fix codeclimate issues

* Fix image controller tests

* Small fixes

* Add rubocop.yml

* Fix rubocop

* Increase linelength

* Fix rubocop

* Rename tests for better readability

* Rename tests

* Fixing Codeclimate offenses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants