Skip to content

Organizations: minor code cleanup #355

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

Merged
merged 3 commits into from
May 18, 2018
Merged

Organizations: minor code cleanup #355

merged 3 commits into from
May 18, 2018

Conversation

markets
Copy link
Collaborator

@markets markets commented May 12, 2018

This is just a minor code cleanup 🔨 (about Organizations):

  • controller: code rearrange and simplification
  • model:
    • remove unused code
    • added validates :name, presence: true
  • views:
    • use show_error_messages!(@organization) to print error messages in form
    • "new" button with pull-right class (for consistency with all "new" buttons)
  • specs: minor cleanup, fix repeated test and add new spec for name presence

We need to properly define and implement an OrganizationPolicy, but this would be a different PR (we should define an access control policy first), this branch only contains some minor refactors, which clarify/simplify code and remove 💀 methods. What do you think guys? The only behavior change is the validation on name presence, which is probably a sane change.

@markets markets force-pushed the orgs_minor_refactor branch from 96fa377 to fdb3120 Compare May 12, 2018 21:12
Copy link
Collaborator

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

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

👏 nice cleanup!

@organizations = Organization.all
end
end
before_filter :load_resource, except: [:new, :index, :create]
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about using only instead? It will feel a bit more under control. Loading it by default in any new action seems dangerous to me.


def new
@organization = Organization.new
end

def index
@organizations = @organizations.matching(params[:q]) if params[:q].present?
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we removing the q param? That will break the search, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I deleted it becasue I can't found any point of the app using this search.

expect(organization).to be_valid
expect(organization.web).to eq "http://www.casa.com"
end
it "with http" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add some spacing between text examples, now that we are at it?

}

validates :name, uniqueness: true
validates :name, presence: true, uniqueness: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make sure we also have null: false and a unique index at db level 🙏

Copy link
Collaborator Author

@markets markets May 14, 2018

Choose a reason for hiding this comment

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

agree @sauloperez I'll review the schema and in case this is missing, I'll create a migration to fix that

Copy link
Contributor

Choose a reason for hiding this comment

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

@markets can you please check this, thanks!!! (no rush of course 😄 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see you did it already here b9d9b96 right?

@markets
Copy link
Collaborator Author

markets commented May 14, 2018

@sauloperez code review changes pushed!

Copy link
Contributor

@enricostano enricostano left a comment

Choose a reason for hiding this comment

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

Nice, thanks @markets !

Would you please mind to add some test note in the description? So who'll pick it to test it will know what to look for. Thanks!

@sseerrggii
Copy link
Contributor

Hi @markets I tested to create a organization, without name now it isn't possible 👏 . Is it enough test?

May be you can help with other improvements in active admin, if you want I can create the issues:

  • I can't delete a organization: If some admin ask to me to remove all timebank I delete all the members (and users if they haven't another membership) and after that I change the name of timebank with something like "to delete someday" 🙏

  • Another annoying thing is when I create a new user and add membership the select of all organitzations show the organitzations without an order, for me will be perfect if they are ordered by ID

😘 😘 😘

@markets
Copy link
Collaborator Author

markets commented May 17, 2018

Hi @sseerrggii thanks a lot! 👏 yes, that test should be enough, as it's the only behavior change here, the rest is just some code cleanup and minor refactors!

About the other couple of points, yes no problem, I can take a look, but in a separated branch. So if you can create a new issue with them, would be 👌

@enricostano
Copy link
Contributor

Thanks @sseerrggii @markets 🎉

May be you can help with other improvements in active admin

Remember that we have a prioritized list of stuff to do in Trello, I would rather start from there 🙏

@enricostano
Copy link
Contributor

@sseerrggii @markets can we give this PR as tested and merge it?

@enricostano
Copy link
Contributor

@markets sorry, would you mind to rebase it from the latest develop? Thanks!

@markets
Copy link
Collaborator Author

markets commented May 18, 2018

@enricostano updated!

@enricostano enricostano merged commit 48b4f1a into develop May 18, 2018
@enricostano enricostano deleted the orgs_minor_refactor branch May 18, 2018 09:33
@enricostano enricostano mentioned this pull request Aug 8, 2018
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.

4 participants