Skip to content

Commit

Permalink
Test - Review / Advert/ AdvertPrice / Level + Level Validate
Browse files Browse the repository at this point in the history
  • Loading branch information
c00221536 committed May 9, 2016
1 parent 6d31b26 commit c4fd34a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 41 deletions.
8 changes: 8 additions & 0 deletions app/models/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ class Level < ActiveRecord::Base
has_many :advert_prices
has_one :degree
has_many :lessons

validates :level, presence: true
validates :code, presence: true
validates :be, presence: true
validates :fr, presence: true
validates :ch, presence: true



end
1 change: 1 addition & 0 deletions app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class Review < ActiveRecord::Base
validates :sender_id, presence: true
validates :subject_id, presence: true
validates_uniqueness_of :subject, :scope => :sender
validates :note, presence: true
end
2 changes: 1 addition & 1 deletion db/migrate/20160211091344_create_levels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def up
t.integer :level, null: false, :default => 1
t.string :code, null: false
t.string :be, null: false
t.string :fr, null:false
t.string :fr, null: false
t.string :ch, null: false
end
end
Expand Down
15 changes: 14 additions & 1 deletion test/models/advert_price_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
require 'test_helper'

class AdvertPriceTest < ActiveSupport::TestCase
test "the truth" do
test "AdvertPrice.count" do
assert_equal 11, AdvertPrice.count
end

test "creationSansParam" do
a = AdvertPrice.new
assert_not a.save
end

test "AdvertPriceNegatif" do
assert 'AdvertPrice.count' do
AdvertPrice.create(:advert => one, :level_id => 5, :price => -5.0)
end
end


end
20 changes: 17 additions & 3 deletions test/models/advert_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
require 'test_helper'

class AdvertTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "Advert.count" do
assert_equal 4, Advert.count
end

test "AdvertSansTopic" do
a = Advert.new
assert_not a.save
end

test "AdvertSameParams" do
assert 'Advert.count' do
Advert.create(:user => 3, :topic_id => 5, :topic_group_id => 2)
end
end



end
12 changes: 9 additions & 3 deletions test/models/level_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'test_helper'

class LevelTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test " Level count" do
assert_equal 30, Level.count
end

test "CreationSansAllParams" do
assert_equal 30, Level.count
Level.create(:level=>7, :be=>"C2 Compétent/Courant", :fr=>"C2 Compétent/Courant", :ch=>"C2 Compétent/Courant")
end

end
12 changes: 9 additions & 3 deletions test/models/review_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'test_helper'

class ReviewTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "Review.count" do
assert_equal 0, Review.count
end

test "creation sans all param" do
assert_difference 'Review.count' do
Review.create(:sender => User.first, :subject => User.second,:note => 5)
end
end
end
39 changes: 9 additions & 30 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
test "users_count" do
test "User.count" do
assert_equal 2, User.count
end

Expand Down Expand Up @@ -37,34 +37,13 @@ class UserTest < ActiveSupport::TestCase
User.first.upgrade
assert User.first.is_a?(Teacher)
end
test "is_prof_accepted" do
assert_not User.first.is_prof
end
test "is_prof_accepted2" do
User.first.upgrade
assert_not User.first.is_prof
end
test "is_prof_accepted3" do
User.first.upgrade
User.first.upgrade
assert_not User.first.is_prof
end
test "is_prof_accepted4" do
User.first.upgrade
User.first.upgrade
User.first.accept_postulance
assert User.first.is_prof
end
test "is_prof_postulant" do
assert_not User.first.is_prof_postulant
end
test "is_prof_postulant2" do
User.first.upgrade
assert_not User.first.is_prof_postulant
end
test "is_prof_postulant3" do
User.first.upgrade
User.first.upgrade
assert User.first.is_prof_postulant

test "create account already existing" do
assert_no_difference 'User.count' do
User.create(:email => "c@c.c", :firstname => "Bonobo", :lastname => "Chauve", :password => "kaltrina", :encrypted_password => "$2a$10$kdhcUGrsb7gBk.RHrs2xK.OHMx5gdx7kmLHFozZgRdtigrlbt91Zu", :confirmation_token => "2016-04-25 08:38:01.794478", :confirmation_sent_at => "2016-04-25 08:38:01.794477", :confirmed_at => "2016-04-25 08:38:01.794477",
:avatar_file_name => "hello3.jpg", :avatar_content_type => "image/jpeg", :avatar_file_size => 64813, :avatar_updated_at => "2016-04-25 09:42:55", :type => 'Teacher')

end
end
end

0 comments on commit c4fd34a

Please sign in to comment.