Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.
If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!
If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!
We're looking to improve our testing to catch errors before they affect our live site! One type is "unit tests" which test models. You can read all about Rails testing here.
https://github.com/publiclab/plots2/blob/master/test/unit/tag_test.rb shows lots of great unit tests, but nothing for the Tag.related() function which is here:
Let's add one to test this out! An initial test could just run it and confirm that it passes anything back. But then as a follow-up we could expand the test to be more comprehensive.
But for starters, we can add a simple test just like this one:
We could add just below the above-mentioned test, something like:
test 'related tags' do
related = Tag.related(tags(:awesome).name)
assert !related.empty?
# assert related.include?(tags(:test)) # if we want to get ambitious, we could check whether an actual related tag is returned, but we would have to probably adjust this if the "test" tag is not actually related.
end
Please email the developers list (see https://publiclab.org//developers) or go to the chatroom if you have questions, and take a look at our first-timers landing page!
I would like to work on this if no one is working on it already.
Hi @yasmindias, unfortunately, this issue is reserved for Google Code-In as mentioned in the issue body, so you have to look for another issue. Thanks!
Hi @yasmindias we'd love to work with you on another issue and are posting more at https://code.publiclab.org soon. Thank you!
This is reserved for @Nirvikalpa108! Thank you!
Hi @jywarren, thank you so much for reserving this issue for me! This is perfect as I really want to learn about testing!
I am still at the very beginning of my coding journey so I'm finding the syntax quite intimidating.
I appreciate the link from the general rails testing docs, is there a particular section or another article or two that could help me get to grips with this issue?
Alternatively, is there anyone that would have an hour to pair with me on this remotely? If not, I would really appreciate receiving some tips on what to google or particular articles so I can teach myself. Thank you 😃
Hi! so glad. 🎉
For starters, yeah, i think this railscast could be helpful -- i learned rails via Railscasts: http://railscasts.com/episodes/327-minitest-with-rails (although it's a bit old, mostly it is still legit)
I looked around a bit and found this which is kind of nice: https://guides.railsgirls.com/test-driven-development
We use minitest and not rspec so be aware a lot of tutorials are for rspec. Basically, though, unit tests are the simplest and best type of test - they test core functions, not overall systems. They test the lowest-level functions one at a time, out of context. By contrast, functional tests test whole URL endpoints of the app, like posting a blog post or logging in. So they basically require running the whole app automatically through some paces. Unit tests just test some minimal step of the process and confirm that the basic behavior acts as it should. Unit tests are fast and "cheap" - and they confirm basic expected behaviors we might use over and over, but they don't guarantee the whole system works together in concert, if you know what i mean. I hope this is helpful!
Also, if you have the codebase up and running already (#3840), you can try pasting the sample test i cited above into test/unit/tag_test.rb and running rake test:units (i believe) to see it run. Specifics on testing in our app can be found here: https://github.com/publiclab/plots2/blob/master/doc/TESTING.md
Testing is kind of satisfying in a funny way. I hope you enjoy this issue! There could be some more test-driven-development steps you could take on next if you're interested! Perhaps, #4232 could be a next challenge?
And here, i'll annotate this a bit:
test 'related tags' do # <== declare the test and what it's supposed to test for
related = Tag.related(tags(:awesome).name) # <== run the `Tag.related()` function and pass it a tag name, which is what it expects to get; store the output in a variable called "related"
assert !related.empty? # <== we assert that whatever it returned is not (!) empty
assert related.include?(tags(:test)) # <== if we want to get ambitious, we could check whether an actual related tag is returned, but we would have to probably adjust this if the "test" tag is not actually related.
end
To find a related tag, you could add this line before the last line of the test:
puts related.to_json # <== here, we output the returned values in JSON and we'll be able to see in the test output what is actually returned. Then we can add that to the test.
This will protect the functionality of Tag.related() against future breaking changes!
Hi @jywarren I just want to say a HUGE thank you for taking the time to set this all out for me, that's incredibly kind of you! I'm looking forward to going through all of the recommended links over the coming days and will let you know once I come across further questions. Thank you!
thank you too! And good luck - i can help out if you get stuck!!!
On Fri, Mar 15, 2019 at 3:34 AM Amina notifications@github.com wrote:
Hi @jywarren https://github.com/jywarren I just want to say a HUGE
thank you for taking the time to set this all out for me, that's incredibly
kind of you! I'm looking forward to going through all of the recommended
links over the coming days and will let you know once I come across further
questions. Thank you!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/3480#issuecomment-473186839,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ4x2K_xcayl2f6OH1DfE6HGRpGuOks5vW0zxgaJpZM4W5XpZ
.
Most helpful comment
This is reserved for @Nirvikalpa108! Thank you!