2015-10-23 19:42:51 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe DownloadTracker do
|
|
|
|
|
|
|
|
|
|
let(:user1) {FactoryGirl.create(:user)}
|
|
|
|
|
let(:user2) {FactoryGirl.create(:user)}
|
|
|
|
|
let(:user3) {FactoryGirl.create(:user)}
|
|
|
|
|
let(:jam_track) {FactoryGirl.create(:jam_track)}
|
|
|
|
|
|
|
|
|
|
describe "check_user_sharer" do
|
|
|
|
|
describe "with max 1" do
|
|
|
|
|
it "and there is one row that is not paid for" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(1)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['user_id'].should eql (user1.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with max 2" do
|
|
|
|
|
|
|
|
|
|
it "and there is one row that is not paid for" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
# and then add that same user at different IP, and see that something shows up
|
|
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from different IP address, different jam tracks" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['user_id'].should eql(user1.id)
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 2
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
# now add a second user with one of the previous IP addresses; shouldn't matter yet
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user2, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['user_id'].should eql(user1.id)
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 2
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from same IP adresss, same jam track" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1', jam_track: jam_track)
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1', jam_track: jam_track)
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user2, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['user_id'].should eql(user1.id)
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 3
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from same user one paid for, one not" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: true, remote_ip: '1.1.1.1')
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_user_sharer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "check_freebie_snarfer" do
|
|
|
|
|
|
|
|
|
|
describe "with max 1" do
|
|
|
|
|
|
|
|
|
|
it "and there is one row that is not paid for" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(1)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there is one row that is paid for" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: true, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(1)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
describe "with max 2" do
|
|
|
|
|
|
|
|
|
|
it "and there is one row that is not paid for" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
# and then add a second user at same IP, and see that something shows up
|
|
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user2, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from same user, different jam tracks" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['remote_ip'].should eql('1.1.1.1')
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 2
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user2, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['remote_ip'].should eql('1.1.1.1')
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 2
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from same user, same jam track" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1', jam_track: jam_track)
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1', jam_track: jam_track)
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '2.2.2.2')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 1
|
2015-10-23 19:42:51 +00:00
|
|
|
results[0]['remote_ip'].should eql('1.1.1.1')
|
2016-07-17 15:16:27 +00:00
|
|
|
results[0]['count'].should eql 3
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "and there are two rows from same user one paid for, one not" do
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: true, remote_ip: '1.1.1.1')
|
|
|
|
|
tracker1 = FactoryGirl.create(:download_tracker, user: user1, paid: false, remote_ip: '1.1.1.1')
|
|
|
|
|
|
|
|
|
|
results = DownloadTracker.check_freebie_snarfer(2)
|
2016-07-17 15:16:27 +00:00
|
|
|
results.all.length.should eq 0
|
2015-10-23 19:42:51 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|