Created
August 13, 2013 17:26
-
-
Save thomas-holmes/6223517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Company < ActiveRecord::Base | |
before_create :generate_api_token | |
attr_accessible :name, :owner, :owner_id | |
validates :name, presence: true, uniqueness: { case_sensitive: false }, :length => { :minimum => 5, :maximum => 40 } | |
validates :owner, presence: true | |
validates :owner_id, presence: true | |
has_many :orders | |
has_many :users | |
private | |
def generate_api_token | |
begin | |
self.token = SecureRandom.urlsafe_base64 | |
end while self.class.exists?(token: self.token) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "when email is not downcased" do | |
before { @company.save } | |
it "should be saved as all lowercase" do | |
saved_company = Company.find(@company.id) | |
@company.name = "Another name" | |
@company.save | |
expect(@company.token).to eq saved_company.token | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment