-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
added specs and validations for Role model #5792
Conversation
class Role < ActiveRecord::Base | ||
belongs_to :person | ||
|
||
validates :person, presence: true | ||
validates :name, uniqueness: {scope: :person_id} | ||
validates :name, inclusion: { in: %w(admin spotlight) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { detected.
Space inside } detected.
Mh, I'm not sure I like shoulda-matchers, it feels inconsistent with the expect syntax. |
@jhass, the one-line syntax used by shoulda-matchers is supported by RSpec, even when using the expect syntax: https://github.com/rspec/rspec-expectations/blob/master/Should.md#one-liners I feel that the inconsistency is a small trade-off for being able to write a one-liner instead of multiple lines. It's a solid Thoughtbot gem with great support & documentation. It's probably saved me hundreds of hours and thousands of lines of spec code over the years. Check it out...let me know what you think...and in the meantime, I'll start making Hound happier... 😄 |
Mh, okay deal, we can try it for a while. |
e4471dc
to
fc45ebd
Compare
@@ -10,6 +10,7 @@ | |||
require 'webmock/rspec' | |||
require 'factory_girl' | |||
require 'sidekiq/testing' | |||
require 'shoulda/matchers' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
fc45ebd
to
6c3f6cb
Compare
@@ -25,39 +26,39 @@ def set_up_friends | |||
end | |||
|
|||
def alice | |||
@alice ||= User.where(:username => 'alice').first | |||
@alice ||= User.where(:username => "alice").first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
- added shoulda-matchers gem for one-line specs - added FactoryGirl syntax methods
6c3f6cb
to
d4f1a5d
Compare
Thank you! |
added specs and validations for Role model
Partial fix for #4020
I also added a few validations that seemed to make sense for roles, and tweaked the
Role.is_admin?
method to return a boolean. Hopefully CI will catch any issues that these changes may cause, but please let me know if I should back out any of those changes to the model itself.