-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fixes #11379: Made the subtopics method #11380
Conversation
Codecov Report
@@ Coverage Diff @@
## main #11380 +/- ##
==========================================
+ Coverage 79.75% 82.42% +2.66%
==========================================
Files 96 96
Lines 5968 5952 -16
==========================================
+ Hits 4760 4906 +146
+ Misses 1208 1046 -162
|
Hi @KarishmaVanwari ok, so, this actually relates to this PR, on topic trees: #11230 (comment) I'm so sorry i mixed these up. But I've made some suggestions and explanations to refine this PR a bit, and you have to expand the "Show resolved" sections above to read them -- please do! Let me know if they make sense? |
app/controllers/tag_controller.rb
Outdated
nodes = Tag.find_by(name: "parent:#{params[:topic]}") # here, we look for this special tag marking a node as having a parent | ||
.nodes | ||
.collect(&:slug) # collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname | ||
render "tags/subtopic", layout: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so here, i think we also have to actually make the partial template, at: /app/views/tags/_subtopics.html.erb
, and for now it can just print out the subtopics. If you'd like, you can look at the HTML you made in #11230 and use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren :
I created the file _subtopics.html.erb
with the following code so as to only print the subtopics when pointed at a URL say http://localhost:3000/tags/subtopic/one
or http://localhost:3000/tags/subtopic/two
:
<% @subtopics.each do |subtopic| %>
<h1><%= subtopic %></h1>
<% end %>
However, it gives an error -
Is it because the tags "one" or "two" do not have any specified subtopics as such? But it doesn't seem so, since I just tried adding a check to see if @subtopics is nil. Let me know your thoughts on this!
Thanks!
Hi @jywarren, I've gone through the explanations and understood my shortcomings and the respective explanations. Thank you so much Jeff for the detailed explanation and for bearing with me while I try to figure out stuff, thanks again! ❤️ |
Hi, Karishma - i'm kind of surprised that your local doesn't show a full
development error log, which would highlight the line number of the error.
How are you starting your development server? And, even if we don't see it
in the browser debug output, we should be able to look in the console logs
to find the exact reason it failed. Let's look!
…On Sat, Sep 3, 2022 at 8:30 PM Karishma Vanwari ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/controllers/tag_controller.rb
<#11380 (comment)>:
> @@ -568,4 +568,10 @@ def fetch_counts
end
def topic_tree; end
+
+ def subtopics
+nodes = Tag.find_by(name: "parent:#{params[:topic]}") # here, we look for this special tag marking a node as having a parent
+ .nodes
+ .collect(&:slug) # collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname
+ render "tags/subtopic", layout: false
@jywarren <https://github.com/jywarren> :
I created the file _subtopics.html.erb with the following code so as to
only print the subtopics when pointed at a URL say
http://localhost:3000/tags/subtopic/one or
http://localhost:3000/tags/subtopic/two:
<% @subtopics.each do |subtopic| %> <h1><%= subtopic %></h1>
<% end %>
However, it gives an error -
[image: image]
<https://user-images.githubusercontent.com/78212650/188291739-bf4052ae-0030-4b76-94e7-536952eabd96.png>
Is it because the tags "one" or "two" do not have any specified subtopics
as such? Let me know if I am wrong.
Thanks!
—
Reply to this email directly, view it on GitHub
<#11380 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J5MVB4FHWWSTF6KSJLV4PUTDANCNFSM6AAAAAAQC3TSWY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Co-authored-by: Jeffrey Warren <[email protected]>
Aha - the subtopics method is in the As much as possible please do push up your local changes to the PR so I can see exactly what you're working with when i open it. Thanks! |
This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here: |
@@ -568,4 +579,5 @@ def fetch_counts | |||
end | |||
|
|||
def topic_tree; end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at class body end.
render "tag/_subtopics", layout: false | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line detected.
# collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname | ||
subtopic_names = Tag.find_by(name: "parent:#{params[:topic]}") | ||
&.nodes | ||
&.collect(&:slug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I pushed a couple commits to fix minor issues. See how I moved this up out of the "private" section.
Also I added &.
which fails gracefully if the value is nil, instead of erroring - it just doesn't continue trying.
I think it should work now, but I think it's worth writing a functional test for this. That will mean adding a tag to a wiki page with name parent:TAGNAME
such that the code actually gets used.
The reason is that for most tags we might test this with, there won't be any subtopics. We need to create some test data to make that situation appear so that we can write a test around it. Make sense? I'm happy to help with the test data, let me know if you'd like some support on that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And great work getting this far. It's complex!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren
I tried opening the page: /tags/subtopic/one
, I am able to successfully render the page (blank although), and I can render topic name also on the page by extracting it from the URL. I created a wiki page with tag parent:one
but I am still unable to fetch subtopics on the page. I doubt if @subtopics
actually carries the subtopics in it.
Also, a mention, on line 531 here, we have
Tag.find_by(name: "parent:#{params[:topic]}")
Here, tag is compared with parent:#{params[:topic]}
, right? So I also tried creating a wiki page with tag parent:#one
but still can't fetch it on the /tags/subtopic/one
page. Conversely, I also tried to change the line 531 to this -
Tag.find_by(name: "parent:{params[:topic]}")
and created a wiki page with tag parent:one
, but still I can't obtain desired result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do you think I have this test data (the wiki pages I created), so as to write a test? Also, I am totally new to writing tests, could you please guide me with it? PS: Sharing resources also would do.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @KarishmaVanwari ok so you are doing really well then, if it rendered a blank page. We just need to debug the controller.
A controller test is known as a functional test -- there is documentation here, but it's pretty dense: https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers
I might start by looking at other tests:
plots2/test/functional/tag_controller_test.rb
Lines 206 to 214 in 4204a62
test 'tag show' do | |
get :show, params: { id: tags(:spectrometer).name } | |
assert :success | |
assert_not_nil :tags | |
# assert_equal assigns['tags'].length, 1 | |
assert_select '#wiki-summary', 1 | |
end |
And at how we create test data -- by creating entries in https://github.com/publiclab/plots2/blob/main/test/fixtures/
For tags, we'll have to create not only a tag fixture entry in https://github.com/publiclab/plots2/blob/main/test/fixtures/tags.yml
but also a record to link that tag to a node: https://github.com/publiclab/plots2/blob/main/test/fixtures/node_tags.yml
Does that make sense? Let's start with that, can you add that to this PR? Once it's in place, I can help you write a simple test, then narrow the test assertions until we find what was wrong with our assumptions. How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, as far as I can tell, your parent:one
tag should work! And here is hopefully a helpful tip - the "line of text with #{something} in the middle"
syntax is a way to insert Ruby code into a string. It must use " double quotes, and the inserted Ruby code to be evaluated is surrounded by #{ }
. It's a little weird looking but it is smoother than adding a bunch of separate strings together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren : I created test data in https://github.com/publiclab/plots2/blob/main/test/fixtures/tags.yml and https://github.com/publiclab/plots2/blob/main/test/fixtures/node_tags.yml. Let me know if I got that right. Thanks!
This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here: |
…into subtopics
Code Climate has analyzed commit 11cdb1c and detected 2 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here: |
subtopic_tag: | ||
tid: 38 | ||
uid: 2 | ||
nid: 41 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but it's applied to this page, which is a note, not a wiki:
https://github.com/KarishmaVanwari/plots2/blob/subtopics/test/fixtures/nodes.yml#L497
Will that affect the logic, and possibly cause it not to return things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it should get the slug for this note, and try to use it as a subtopic tagname, according to this logic:
Aha - yes, so, then it takes the slug from that page, which is "jeff-12-20-2020-ouija-board" - and tries to find a tag with that name. It doesn't find one, so it returns null.
Let's change this to instead point at this node, which is a page, with slug about
. Then let's add a new tag with the name about
so that there is actually a tag that can be returned.
We could give these more realistic tag names so it makes more sense... but, maybe it's not worth it for now. Let's just get it working first.
nid: 41 | |
nid: 2 |
So now you'll also have to add a new tags.yml entry, but it doesn't need a node_tags.yml entry, since we only look if the tag exists, not if we used it anywhere. Let's see how that works!
subtopic_names = Tag.find_by(name: "parent:#{params[:topic]}") | ||
&.nodes | ||
&.collect(&:slug) | ||
@subtopics = Tag.find_by(name: subtopic_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying this locally and this line returns nil,,, the subtopic_names
variable above returns slugs of the nodes' title downcase & hyphenated -- from the comment seems we are expecting this to be tagname slugs that maybe the issue
Hi 😄, this issue has been automatically marked as stale because it has not had recent activity. Don't worry you can continue to work on this and ask @publiclab/reviewers to add |
Fixes #11379
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
rake test
@publiclab/reviewers
for help, in a comment below