?", "active") end def self.all_inactive where("state = ?", "inactive") end def active? self.state == 'active' end def inactive? self.state == 'inactive' end end
'inactive'] class <<self STATES.each do |state_name| define_method "all_#{state_name}" do where("state = ?", state_name) end end end STATES.each do |state_name| define_method "#{state_name}?" do self.state == state_name end end end
validates :lastname, presence: true validates :email, presence: true, uniqueness: true end describe User do it "é válido quando nome, último nome e email estão presentes" do user = User.new( firstname: 'Bruce', lastname: 'Dickinson', email: '[email protected]' ) expect(user).to be_valid end end