Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gasb150 committed Mar 7, 2021
1 parent eee17c1 commit f8a0859
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 17 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--require spec_helper
--format documentation
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ group :test do
gem 'capybara', '>= 3.26'
gem 'rspec'
gem 'selenium-webdriver'
gem 'shoulda-matchers', '~> 4.5', '>= 4.5.1'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end

gem 'active_storage_validations'
gem 'hirb'
gem 'cloudinary'

Expand Down
23 changes: 13 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage_validations (0.9.2)
rails (>= 5.2.0)
activejob (6.1.3)
activesupport (= 6.1.3)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -88,9 +90,9 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (3.0.0)
cloudinary (1.18.1)
cloudinary (1.19.0)
aws_cf_signer
rest-client
rest-client (>= 2.0.0)
coderay (1.1.3)
concurrent-ruby (1.1.8)
crass (1.0.6)
Expand All @@ -105,7 +107,7 @@ GEM
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
erubi (1.10.0)
ffi (1.14.2)
ffi (1.15.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
hirb (0.7.3)
Expand Down Expand Up @@ -136,12 +138,10 @@ GEM
minitest (5.14.4)
msgpack (1.4.2)
netrc (0.11.0)
nio4r (2.5.5)
nio4r (2.5.7)
nokogiri (1.11.1)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
nokogiri (1.11.1-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.20.1)
parser (3.0.0.0)
Expand Down Expand Up @@ -211,7 +211,7 @@ GEM
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (4.0.2)
rspec-rails (4.1.0)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
Expand Down Expand Up @@ -246,7 +246,9 @@ GEM
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
semantic_range (2.3.1)
semantic_range (3.0.0)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
simple_form (5.1.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
Expand Down Expand Up @@ -295,9 +297,9 @@ GEM

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
active_storage_validations
better_errors
binding_of_caller
bootsnap (>= 1.4.4)
Expand All @@ -318,6 +320,7 @@ DEPENDENCIES
rubocop
sass-rails (>= 6)
selenium-webdriver
shoulda-matchers (~> 4.5, >= 4.5.1)
simple_form
spring
turbolinks (~> 5)
Expand All @@ -330,4 +333,4 @@ RUBY VERSION
ruby 2.7.2p137

BUNDLED WITH
2.2.8
2.1.4
10 changes: 10 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
# Bullet.growl = true
Bullet.rails_logger = true
Bullet.add_footer = true
end

config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Expand Down
10 changes: 5 additions & 5 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# and recreated between test runs. Don't rely on the data there!

Rails.application.configure do
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.raise = true # raise an error if n+1 query occurs
end
# config.after_initialize do
# Bullet.enable = true
# Bullet.bullet_logger = true
# Bullet.raise = true # raise an error if n+1 query occurs
# end

# Settings specified here will take precedence over those in config/application.rb.

Expand Down
7 changes: 6 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!

Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
require 'active_storage_validations/matchers'
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.include ActiveStorageValidations::Matchers
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
Expand Down
11 changes: 11 additions & 0 deletions spec/unit-test/articles_category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rails_helper'
RSpec.describe ArticlesCategory, type: :model do
describe 'assosiations' do
it { should belong_to(:article)}
it { should belong_to(:category)}
end
describe 'Articles Categories attributes presence' do
it { should validate_presence_of(:article_id) }
it { should validate_presence_of(:category_id) }
end
end
36 changes: 36 additions & 0 deletions spec/unit-test/articles_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'

RSpec.describe Article, type: :model do
describe 'assosiations' do
it { should belong_to(:user) }
it { should have_many(:votes) }
it { should have_one_attached(:image) }
it { should have_many(:articles_categories) }

end
describe 'title presence' do
it { should validate_presence_of(:title) }
end

describe 'text presence' do
it { should validate_presence_of(:text) }
end



describe 'category ids presence' do
it { should validate_presence_of(:category_ids) }
end
describe 'image presence' do
it { should validate_presence_of(:image) }
end

describe 'lenght of title' do
it { should validate_length_of(:title) }
end
describe 'lenght of text' do
it { should validate_length_of(:text) }
end


end
14 changes: 14 additions & 0 deletions spec/unit-test/category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rails_helper'

RSpec.describe Category, type: :model do

describe 'assosiations' do
it{should have_many (:articles_categories)}
it{should have_many (:articles)}
end

describe 'Category attributes presence' do
it {should validate_presence_of (:name)}
it {should validate_presence_of (:priority)}
end
end
31 changes: 31 additions & 0 deletions spec/unit-test/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'
RSpec.describe User, type: :model do

subject(:user) { User.new(username: '7aves', name: 'Gustave', email: '[email protected]', password: "example") }

describe 'assosiations' do
it {should have_many(:articles)}
it {should have_many(:votes)}
end
describe 'valid atributes' do
it 'is valid with all attributes' do
expect(user).to be_valid
end
it 'is not valid without a name' do
user.name = nil
expect(user).to_not be_valid
end
it 'is not valid without a username' do
user.username = nil
expect(user).to_not be_valid
end
it 'is not valid without a email' do
user.email = nil
expect(user).to_not be_valid
end
it 'is not valid without a password' do
user.password = nil
expect(user).to_not be_valid
end
end
end
12 changes: 12 additions & 0 deletions spec/unit-test/vote_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'
RSpec.describe Vote, type: :model do

describe 'assosiations' do
it { should belong_to(:article)}
it { should belong_to(:user)}
end
describe 'vote attributes presence' do
it { should validate_presence_of(:article_id) }
it { should validate_presence_of(:user_id) }
end
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ class ActiveSupport::TestCase

# Add more helper methods to be used by all tests here...
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :rails
end
end

0 comments on commit f8a0859

Please sign in to comment.