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

Remove "parent" in tag.rb #9404

Merged
merged 4 commits into from
Apr 17, 2021
Merged

Remove "parent" in tag.rb #9404

merged 4 commits into from
Apr 17, 2021

Conversation

jcads
Copy link
Contributor

@jcads jcads commented Mar 31, 2021

Fixes #9403

Remove:

  • any instance of the word "parent" in tag.rb
  • def add_parent
    if logged_in_as(['admin'])
    @tag = Tag.find_by(name: params[:name])
    @tag.update_attribute('parent', params[:parent])
    if @tag.save
    flash[:notice] = "Tag parent added."
    else
    flash[:error] = "There was an error adding a tag parent."
    end
    redirect_to '/tag/' + @tag.name + '?_=' + Time.now.to_i.to_s
    else
    flash[:error] = "Only admins may add tag parents."
    end
    end
  • get 'tag/parent' => 'tag#add_parent'
  • before_action :require_user, only: %i(create delete add_parent)

Removing the above should cause the following tests to fail, so remove relevant tests in:

  • plots2/test/unit/node_tag_test.rb
  • plots2/test/functional/tag_controller_test.rb

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • ask @publiclab/reviewers for help, in a comment below

@gitpod-io
Copy link

gitpod-io bot commented Mar 31, 2021

app/models/tag.rb Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@ebaad12). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 2301891 differs from pull request most recent head cc8274a. Consider uploading reports for the commit cc8274a to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9404   +/-   ##
=======================================
  Coverage        ?   58.44%           
=======================================
  Files           ?       98           
  Lines           ?     5985           
  Branches        ?        0           
=======================================
  Hits            ?     3498           
  Misses          ?     2487           
  Partials        ?        0           

@jcads
Copy link
Contributor Author

jcads commented Mar 31, 2021

@jywarren kindly review if I made the correct changes in tag.rb. Thanks!

@jcads jcads force-pushed the migrate-new-tags branch from fe7394f to b8a1b11 Compare March 31, 2021 09:21
Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Gosh, love seeing all this code go away!

I think i found a small mistake at before_action and suggested a fix. I hope that resolves the tests but we can look closer at what goes wrong in the tests if not!

Thank you very much and apologies for the slow review. Please feel free to highlight PRs that need review in the chatroom at https://gitter.im/publiclab/publiclab if we miss them, and thanks for your patience!!

@@ -1,6 +1,5 @@
class TagController < ApplicationController
respond_to :html, :xml, :json, :ics
before_action :require_user, only: %i(create delete add_parent)
Copy link
Member

Choose a reason for hiding this comment

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

Hi, actually here I believe we need to remove just the add_parent part, but keep the rest of the line!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok, got it!

app/controllers/tag_controller.rb Show resolved Hide resolved
order = 'node_revisions.timestamp DESC'
order = 'created DESC' if type == 'note'
Node.where('node.nid IN (?)', (nodes + parents).collect(&:nid))
Node.where('node.nid IN (?)', nodes.collect(&:nid))
Copy link
Member

Choose a reason for hiding this comment

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

Nicely done here! Actually we should be able to remove the comment on line 103 too, also related to parenting:

# .where('term_data.name IN (?) OR term_data.parent in (?)', tagnames, tagnames) # greedily fetch children

@@ -342,13 +333,13 @@ def self.tagged_nodes_by_author(tagname, user_id)
if tagname[-1..-1] == '*'
@wildcard = true
Node.includes(:node_tag, :tag)
.where('term_data.name LIKE(?) OR term_data.parent LIKE (?)', tagname[0..-2] + '%', tagname[0..-2] + '%')
.where('term_data.name LIKE(?)', tagname[0..-2] + '%')
Copy link
Member

Choose a reason for hiding this comment

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

Nice, so much simpler!

config/routes.rb Show resolved Hide resolved
@jcads jcads requested a review from jywarren April 14, 2021 12:44
@jcads
Copy link
Contributor Author

jcads commented Apr 14, 2021

I don't know why there are conflicts though. It seems like it was just the code I removed.

@RuthNjeri
Copy link
Contributor

@jcads, the conflict seems related to the tests https://github.com/publiclab/plots2/pull/9404/conflicts
Screenshot 2021-04-15 at 22 19 56

@codeclimate
Copy link

codeclimate bot commented Apr 16, 2021

Code Climate has analyzed commit cc8274a and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Style 1

View more on Code Climate.

@jywarren jywarren merged commit aaeb5e6 into publiclab:main Apr 17, 2021
@jywarren
Copy link
Member

Awesome work, thank you so much!!!!

@jcads jcads deleted the migrate-new-tags branch April 17, 2021 07:27
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* remove parent publiclab#9403

* remove "parent"

* Fix test errors
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* remove parent publiclab#9403

* remove "parent"

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

Successfully merging this pull request may close these issues.

Remove instances of "parent" in tag.rb
3 participants