forked from joshsoftware/code-curiosity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request joshsoftware#216 from prasadsurase/soft-delete-repos
Soft delete repositories.
- Loading branch information
Showing
5 changed files
with
67 additions
and
1 deletion.
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
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
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 |
---|---|---|
|
@@ -112,4 +112,54 @@ def stub_get(path, endpoint = Github.endpoint.to_s) | |
assert_nil parent_repo.source_gh_id | ||
end | ||
|
||
test 'destroy the repository if it is already persisted if the rating has dropped' do | ||
repo = create :repository, name: 'code-curiosity', ssh_url: '[email protected]:prasadsurase/code-curiosity.git', | ||
owner: 'prasadsurase', stars: 26, gh_id: 67219068 | ||
@user.repositories << repo | ||
@user.save | ||
User.any_instance.stubs(:fetch_all_github_repos).returns( | ||
JSON.parse(File.read('test/fixtures/repos.json')).collect{|i| Hashie::Mash.new(i)} | ||
) | ||
Repository.any_instance.stubs(:info).returns( | ||
Hashie::Mash.new(JSON.parse(File.read('test/fixtures/user-fork-repo.json'))) | ||
) | ||
assert_nil repo.deleted_at | ||
assert_equal 1, Repository.count | ||
assert_equal 26, repo.stars | ||
UserReposJob.perform_now(@user) | ||
repo.reload | ||
refute_nil repo.deleted_at | ||
assert repo.destroyed? | ||
assert_equal 1, Repository.unscoped.count | ||
assert_equal 0, Repository.count | ||
assert_equal 24, repo.info.stargazers_count | ||
assert_equal 24, repo.stars | ||
end | ||
|
||
test 'restore the repository if it is already persisted and destroyed if the rating has increased' do | ||
repo = create :repository, name: 'code-curiosity', ssh_url: '[email protected]:prasadsurase/code-curiosity.git', | ||
owner: 'prasadsurase', stars: 24, gh_id: 67219068, deleted_at: Time.now - 2.days | ||
@user.repositories << repo | ||
@user.save | ||
User.any_instance.stubs(:fetch_all_github_repos).returns( | ||
JSON.parse(File.read('test/fixtures/repos.json')).collect{|i| Hashie::Mash.new(i)} | ||
) | ||
Repository.any_instance.stubs(:info).returns( | ||
Hashie::Mash.new(JSON.parse(File.read('test/fixtures/repo.json'))) | ||
) | ||
refute_nil repo.deleted_at | ||
assert repo.destroyed? | ||
assert_equal 24, repo.stars | ||
assert_equal 0, Repository.count | ||
assert_equal 1, Repository.unscoped.count | ||
UserReposJob.perform_now(@user) | ||
repo.reload | ||
refute repo.destroyed? | ||
assert_nil repo.deleted_at | ||
assert_equal 1, Repository.unscoped.count | ||
assert_equal 1, Repository.count | ||
assert_equal 25, repo.info.stargazers_count | ||
assert_equal 25, repo.stars | ||
end | ||
|
||
end |