-
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
Changes from all commits
669acd0
d195a96
31ba768
9d73d03
3ab03cc
908f3ee
e76687d
c7cc324
f4d90c8
e220ca5
517175f
11cdb1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,17 @@ def comments | |
render 'show' | ||
end | ||
|
||
def subtopics | ||
# here, we look for this special tag marking a node as having a parent | ||
# 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) | ||
@subtopics = Tag.find_by(name: subtopic_names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying this locally and this line returns nil,,, the |
||
render "tag/_subtopics", layout: false | ||
end | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra blank line detected. |
||
private | ||
|
||
def order_string | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at class body end. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% @subtopics&.each do |subtopic| %> | ||
<h1><%= subtopic %></h1> | ||
<% end %> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -284,3 +284,9 @@ sub_tag: | |||||
tid: 37 | ||||||
nid: 1 | ||||||
uid: 2 | ||||||
|
||||||
subtopic_tag: | ||||||
tid: 38 | ||||||
uid: 2 | ||||||
nid: 41 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 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.
Suggested change
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! |
||||||
date: <%= DateTime.now.to_i %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,3 +150,7 @@ hidden_response_tag: | |
subscribed_tag: | ||
tid: 37 | ||
name: sub:tag | ||
|
||
subtopic_tag: | ||
tid: 38 | ||
name: parent:one |
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 tagparent: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
Here, tag is compared with
parent:#{params[:topic]}
, right? So I also tried creating a wiki page with tagparent:#one
but still can't fetch it on the/tags/subtopic/one
page. Conversely, I also tried to change the line 531 to this -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
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!