Skip to content

Commit

Permalink
RSpec model tests initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Vincent committed Feb 17, 2017
1 parent 64ec596 commit 5ccf0a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ If graphs are not showing up run `$rake highcharts:update`
## Built With

* [Devise](https://github.com/plataformatec/devise) - Authentication framework
* [delayed_job](https://github.com/collectiveidea/delayed_job_active_record) - Background processing
* [delayed_job](https://github.com/collectiveidea/delayed_job_active_record) - Background job processing
* [active_Admin](https://github.com/activeadmin/activeadmin) - Administration framework
* [lazy_high_charts](https://github.com/michelson/lazy_high_charts) - To use HighCharts from ruby code
* [lazy_high_charts](https://github.com/michelson/lazy_high_charts) - To use HighCharts with ruby code

## Contributing

Expand Down
1 change: 1 addition & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Domain < ActiveRecord::Base
belongs_to :user
has_many :ranks, dependent: :destroy
validates_uniqueness_of :name, scope: :user_id, message: "You alredy entered that domain"
validates_presence_of :name
validate :user_quota, on: :create

def user_quota
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class User < ActiveRecord::Base
has_many :daily_ranks
has_many :domains
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
Expand Down
20 changes: 19 additions & 1 deletion spec/models/domain_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
require 'rails_helper'

RSpec.describe Domain, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
it " - cannot create a new domain if user already have 3 domains" do
user = User.create!(name: "John Doe", email: '[email protected]', password: 'pw1234@123',
password_confirmation: 'pw1234@123')
user_domain1 = Domain.create!(name: 'http://example1.com', user_id: user.id,
created_at: DateTime.now, updated_at: DateTime.now)
expect(user_domain1.errors).to be_empty

user_domain2 = Domain.create!(name: 'http://example2.com', user_id: user.id,
created_at: DateTime.now, updated_at: DateTime.now)
expect(user_domain1.errors).to be_empty

user_domain3 = Domain.create!(name: 'http://example3.com', user_id: user.id,
created_at: DateTime.now, updated_at: DateTime.now)
expect(user_domain1.errors).to be_empty

user_domain1 = Domain.create(name: 'http://example4.com', user_id: user.id,
created_at: DateTime.now, updated_at: DateTime.now)
expect(user_domain1.errors.full_messages.first).to eq "OOps!!! You have Exceeded maximum domain limit/user (3)"
end
end

0 comments on commit 5ccf0a0

Please sign in to comment.