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

Instagram pattern #2859

Merged
merged 8 commits into from Oct 30, 2018
Merged

Conversation

albarnaz
Copy link
Contributor

Issue: #1760

There is no suggestion in the Instagram empty field in enterprise profile setup menu. Some users copy-paste the full URL on their page. That doesn't work because what is expected is only their Instagram user pseudo.

image

FIX

Add an before save to check if the user enter the whole URL, and extract and store just the handle.

So, if the user enter "www.instagram.com/my_user", we store just "@my_user".

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Thank you! This is great.

Since there are some detours in the commit history, we should squash the commits when merging.

Would you like to continue working on this? I have some ideas how to further improve this.

  1. Use a more precise regular expression to test the URL. Your current test would fail if someone had the handle @i_love_instagram.com which is valid.
  2. Convert your before_save check into a before_validation check.
  3. Include a validation check for the handle. I think it would be a regex like /^@[a-zA-Z0-9._]{1,30}$/.

@sobrinho
Copy link

Maybe we can do something like:

validates :instagram, format: /\A@[a-zA-Z0-9._]{1,30}\z/

def instagram=(value)
  write_attribute(:instagram, value.try!(:gsub, %r{\Ahttps?://(?:www.)?instagram.com/([a-zA-Z0-9._]{1,30})/?\z}, '@\1'))
end

That way we care about that manipulating on setter and we care about the format on the validation.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Wow, this is so much better than my suggestions. I commented on a few things below that can still be improved.

app/models/enterprise.rb Outdated Show resolved Hide resolved
app/models/enterprise.rb Outdated Show resolved Hide resolved
spec/models/enterprise_spec.rb Show resolved Hide resolved
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice! Thank you. That's really good now.

@sigmundpetersen
Copy link
Contributor

How is this related to #2849 ? Can the other be closed or are they complementary? @albarnaz

Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

nice!

@luisramos0
Copy link
Contributor

they are complementary @sigmundpetersen

@luisramos0 luisramos0 added the pr-staged-fr staging.coopcircuits.fr label Oct 26, 2018
@RachL RachL self-assigned this Oct 26, 2018
@luisramos0
Copy link
Contributor

staged: https://staging.openfoodfrance.org

@RachL
Copy link
Contributor

RachL commented Oct 26, 2018

@RachL RachL removed the pr-staged-fr staging.coopcircuits.fr label Oct 26, 2018
@mkllnk mkllnk merged commit 7609496 into openfoodfoundation:master Oct 30, 2018
@sstead sstead mentioned this pull request Nov 9, 2018
@mkllnk
Copy link
Member

mkllnk commented Nov 9, 2018

@RachL Sally found an issue with this pull request: #2849 (comment)

We should have included in the test description that you need to check on a profile page if the Instagram link is actually working. :-D

@RachL
Copy link
Contributor

RachL commented Nov 9, 2018

@mkllnk @sstead ouch my bad :/ But I've re-tested in our production and we don't get the error. Everything saves correctly, so I'm not sure if it was introduce by 2849. But anyway now it is reverted.

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.

None yet

6 participants