Skip to content
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

Unit test for models bet and lot #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
/log/*.log
/tmp

.idea/
.idea/

#ignore rvmrc
.rvmrc
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
require "rails/test_unit/railtie"

if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/bets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
44 changes: 44 additions & 0 deletions test/unit/bet_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'minitest_helper'

class BetTest < ActiveSupport::TestCase
def setup

@lot = Lot.create(name: "test name", male: false, link: "test", photo: "linkphoto", photo_big: "linkphotobig")
@lot.bets.each do |bet|
bet.destroy
end
@lot.bets.create(value: 50)
@lot.bets.create(value: 100)
@lot.bets.create(value: 150)
@lot.bets.create(value: 200)
end

test "soult create new bed" do
bet = @lot.bets.new
bet.value = 250
assert bet.save
end

test "lot_id can not be null" do
bet = Bet.new
bet.value = 250
begin
assert_nothing_raised(ActiveRecord::RecordNotFound) do
assert !bet.save
end
rescue ActiveRecord::RecordNotFound => e
assert(false, e)
end

end

test "validate bet value" do
bet = @lot.bets.new
bet.value = 150
assert !bet.save

bet = @lot.bets.new
bet.value = 350
assert bet.save
end
end
75 changes: 75 additions & 0 deletions test/unit/lot_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'minitest_helper'

class LotTest < ActiveSupport::TestCase


def setup
@prev_lot = Lot.create(name: "test name", male: false, link: "test1", photo: "linkphoto1", photo_big: "linkphotobig1")
@lot = Lot.create(name: "test name2", male: false, link: "test2", photo: "linkphoto2", photo_big: "linkphotobig2")
@lot.bets.each do |bet|
bet.destroy
end
@lot.bets.create(value: 50)
@lot.bets.create(value: 100)
@lot.bets.create(value: 150)
@lot.bets.create(value: 200)

@next_lot = Lot.create(name: "test name3", male: false, link: "test3", photo: "linkphoto3", photo_big: "linkphotobig3")
end

test "Should report validate error name link photo photo_big" do
lot = Lot.new
assert(!lot.save,"valid fields can not be empty")
end

test "Should create new lot" do
lot = Lot.new
lot.name = "Test name"
lot.male = true
lot.link = "http://testlink"
lot.photo = "http://testlink"
lot.photo_big = "http://testlink"
assert lot.save
end


test "name should be unique" do
assert !Lot.create(name: "test name", male: false, link: "tesasdft1", photo: "linkpffghfghdfghoto1", photo_big: "linkpgfhjfghjfghhotobig1")
end

test "link should be unique" do
assert !Lot.create(name: "bbbbbbb", male: false, link: "test1", photo: "l44444", photo_big: "l444444")
end

test "photo should be unique" do
assert !Lot.create(name: "cccccc", male: false, link: "555555", photo: "linkphoto3", photo_big: "55555")
end

test "photo_big should be unique" do
assert !Lot.create(name: "dddddd", male: false, link: "66666", photo: "6666", photo_big: "linkphotobig3")
end

test "Should return current_bet" do
assert(@lot.current_bet.value == 200)
end

test "Should return prev bets" do
assert(@lot.prev_bets.count == 3)
end

test "Should return next lot" do
assert(@prev_lot.next.id == @lot.id)
assert(@prev_lot.next.next.id == @lot.next.id)
assert(@prev_lot.next.next.id == @next_lot.id)
assert(@lot.next.id == @next_lot.id)
end

test "Should return prev lot" do
assert(@next_lot.prev.id == @lot.id)
assert(@next_lot.prev.prev.id == @lot.prev.id)
assert(@next_lot.prev.prev.id == @prev_lot.id)
assert(@lot.prev.id == @prev_lot.id)
end


end