prevent duplicate services from being created
This commit is contained in:
parent
902edb6745
commit
4fb4f71169
2 changed files with 8 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ class Service < ActiveRecord::Base
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
validates_uniqueness_of :uid, :scope => :type
|
||||||
has_many :service_users, :dependent => :destroy
|
has_many :service_users, :dependent => :destroy
|
||||||
|
|
||||||
def public_message(post, length, url = "")
|
def public_message(post, length, url = "")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,13 @@ describe Service do
|
||||||
@user.services << @service
|
@user.services << @service
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is unique to a user by service type and uid' do
|
||||||
|
@service.save
|
||||||
|
@user.services << Services::Facebook.new(:access_token => "yeah")
|
||||||
|
@user.services[1].valid?.should be_false
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it 'destroys the associated service_user' do
|
it 'destroys the associated service_user' do
|
||||||
@service.service_users = [ServiceUser.create(:service_id => @service.id,
|
@service.service_users = [ServiceUser.create(:service_id => @service.id,
|
||||||
:uid => "abc123",
|
:uid => "abc123",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue