-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Factories to create test data (#3)
Added Factories to create test data
- Loading branch information
Showing
4 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
FactoryGirl.define do | ||
|
||
factory :user, :class => OpenStruct do | ||
skip_create | ||
id nil | ||
login Faker::Internet.user_name | ||
name Faker::Name.name | ||
email Faker::Internet.email | ||
company nil | ||
fake false | ||
deleted false | ||
long nil | ||
lat nil | ||
country_code nil | ||
state nil | ||
city nil | ||
location nil | ||
created_at DateTime.now | ||
|
||
transient do | ||
db_obj nil | ||
end | ||
|
||
after(:create) do | user, evaluator | | ||
user.db_obj = evaluator.db_obj | ||
hashed = build(:user).to_h | ||
user.id = user.db_obj[:users].insert(hashed) if user.db_obj | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
require 'test_helper' | ||
include FactoryGirl::Syntax::Methods | ||
|
||
describe 'GhtRetrieveRepo' do | ||
it 'test_it_does_something_useful' do | ||
assert true # this will result in a failure | ||
end | ||
|
||
it 'test_load_ght_retrieve_repo' do | ||
ght = GHTRetrieveRepo.new | ||
err = ->{ ght.go() }.must_raise RuntimeError | ||
err.message.must_match /Unimplemented/ | ||
end | ||
|
||
it 'test_load_ghtorrent.new()' do | ||
ght = GHTRetrieveRepo.new | ||
err = -> { ght.validate }.must_raise RuntimeError | ||
err.message.must_match /Unimplemented/ | ||
end | ||
end | ||
|
||
class GhtorrentTest < Minitest::Test | ||
describe 'ghtorrent::mirror module' do | ||
before do | ||
session = 1 | ||
|
@@ -88,11 +72,136 @@ | |
|
||
it 'should test the ensure_user method' do | ||
users = @ght.db[:users] | ||
user = users.where(:name => 'matthew').first | ||
byebug | ||
@ght.ensure_user(user) | ||
user = users.where(:login => 'msk999').first | ||
returned_user = @ght.ensure_user(user[:login], false, false) | ||
assert returned_user == user | ||
end | ||
|
||
it 'ensure_user method should not return a user if given a bad email' do | ||
assert @ght.ensure_user('[email protected]').nil? | ||
end | ||
|
||
it 'ensure_user should find correct user if given a name and email' do | ||
users = @ght.db[:users] | ||
user = users.where(:login => 'msk999').first | ||
GHTorrent::Mirror.any_instance.stubs(:ensure_user_byemail).returns(user) | ||
returned_user = @ght.ensure_user("#{user[:login]}<[email protected]>", false, false) | ||
assert returned_user == user | ||
end | ||
|
||
it 'ensure_user should not find a user if given a bad user name only' do | ||
returned_user = @ght.ensure_user("~999~$", false, false) | ||
assert returned_user.nil? | ||
end | ||
|
||
it 'should return a user given an email and user' do | ||
email = '[email protected]' | ||
returned_user = @ght.ensure_user_byemail(email, 'msk999') | ||
assert returned_user[:email] == email | ||
end | ||
|
||
it 'should return a user given a bad email and user' do | ||
fake_email = '[email protected]' | ||
returned_user = @ght.ensure_user_byemail(fake_email, 'msk999') | ||
assert returned_user | ||
assert returned_user[:email] == fake_email | ||
assert returned_user[:name] == 'msk999' | ||
|
||
users = @ght.db[:users] | ||
users.where(:email => fake_email).delete | ||
end | ||
|
||
it 'should return a repo given a user and repo' do | ||
repo = @ght.ensure_repo('msk999', 'Subscribem') | ||
assert repo | ||
end | ||
|
||
it 'should not return a repo given a user and bad repo' do | ||
repo = @ght.ensure_repo('msk999', 'Subscribem-z') | ||
assert repo.nil? | ||
end | ||
it 'should not return a repo given a bad user' do | ||
repo = @ght.ensure_repo('msk999z', 'Subscribem') | ||
assert repo.nil? | ||
end | ||
|
||
it 'should return a repo given a user and missing repo' do | ||
user_id = @ght.ensure_user('msk999', false, false)[:id] | ||
repos = @ght.db[:projects] | ||
# change the name of a valid repo so it can't be found | ||
repos.where(:owner_id => user_id, :name => 'Subscribem').update(:name => 'Fake_repo') | ||
repo = @ght.ensure_repo('msk999', 'Subscribem') | ||
assert repo | ||
end | ||
|
||
it 'should ensure the repo returns languague info' do | ||
langs = @ght.ensure_languages('msk999', 'Subscribem') | ||
assert langs | ||
end | ||
|
||
it 'should ensure the invalid repo does not return languague info' do | ||
langs = @ght.ensure_languages('msk999', 'fake_repo') | ||
assert langs.nil? | ||
end | ||
|
||
it 'calls ensure_repo_recursive - not sure what this does' do | ||
retval = @ght.ensure_repo_recursive('msk999', 'Subscribem') | ||
assert retval | ||
end | ||
|
||
it 'calls ensure_commit method' do | ||
users = @ght.db[:users] | ||
user = users.where(:login => 'msk999').first | ||
project_id = @ght.db[:projects].where(:owner_id => user[:id]).first[:id] | ||
sha = @ght.db[:commits].where(:project_id => project_id).first[:sha] | ||
|
||
commit = @ght.ensure_commit('Subscribem', sha, 'msk999') | ||
assert commit[:sha] == sha | ||
assert commit[:project_id] == project_id | ||
end | ||
|
||
it ' calls ensure_commits method' do | ||
users = @ght.db[:users] | ||
user = users.where(:login => 'msk999').first | ||
project_id = @ght.db[:projects].where(:owner_id => user[:id]).first[:id] | ||
sha = @ght.db[:commits].where(:project_id => project_id).first[:sha] | ||
|
||
commit = @ght.ensure_commits('msk999', 'Subscribem', sha: sha, return_retrieved: true, fork_all: true) | ||
assert commit[0][:sha] == sha | ||
end | ||
|
||
it 'should create persist a fake user' do | ||
user = create(:user, db_obj: @ght.db) | ||
assert user | ||
saved_user = @ght.db[:users].where(id: user.id).first | ||
saved_user[:name].must_equal user.name | ||
end | ||
|
||
it 'should not persist a fake user' do | ||
user = create(:user) | ||
assert user | ||
@ght.db[:users].where(login: user.login).count.must_equal 0 | ||
end | ||
|
||
it 'tries to store an invalid commit - need to put this one into transaction' do | ||
users = @ght.db[:users] | ||
user = users.where(:login => 'msk999').first | ||
project_id = @ght.db[:projects].where(:owner_id => user[:id]).first[:id] | ||
sha = @ght.db[:commits].where(:project_id => project_id).first[:sha] | ||
commit = @ght.db[:commits].where(:sha => '10').first | ||
commit = @ght.retrieve_commit('Subscribem', sha, 'msk999') | ||
|
||
# make commit sha invalid | ||
commit['sha'] = '10' | ||
retval = @ght.store_commit(commit, 'subscribem', 'msk999') | ||
assert retval | ||
end | ||
|
||
it 'calls ensure_user_follower method' do | ||
retval = @ght.ensure_user_follower('msk999', 'msk999') | ||
end | ||
end | ||
|
||
# it 'should run if arguments are given' do | ||
# ARGV[0] = 'msk999' | ||
# ARGV << 'Subscribem' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters