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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Enterprise < ActiveRecord::Base
before_validation :set_unused_address_fields
after_validation :geocode_address

before_save :check_instagram_pattern

after_touch :touch_distributors
after_create :set_default_contact
after_create :relate_to_owners_enterprises
Expand Down Expand Up @@ -425,4 +427,9 @@ def touch_distributors
where('enterprises.id != ?', self.id).
each(&:touch)
end

def check_instagram_pattern
return if self.instagram.blank? || self.instagram.exclude?('instagram.com')
self.instagram = "@#{self.instagram.split('/').last}"
end
end
8 changes: 8 additions & 0 deletions spec/models/enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@
it "sets the enterprise contact to the owner by default" do
enterprise.contact.should eq enterprise.owner
end

context "prevent an wrong instagram link pattern" do
let!(:e) { create(:enterprise, instagram: 'www.instagram.com/my_user') }

it "expects the instagram attribute to be in the correct pattern" do
expect(e.instagram).to eq('@my_user')
end
end
end

describe "preferred_shopfront_taxon_order" do
Expand Down