Created
June 9, 2019 18:28
-
-
Save llpereiras/802ab5e156be169df12ca80f5502f116 to your computer and use it in GitHub Desktop.
Teste module em ruby
This file contains hidden or 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
module Twitter | |
module Rules | |
def sort_relevants_followers_retweet_favourites(comments) | |
comments.sort_by do |t| | |
[ -t["followers_count"].to_i, -t["retweet_count"].to_i, -t["favourites_count"].to_i] | |
end | |
end | |
def sort_mentions_followers_retweet_favourites(comments) | |
comments.sort_by do |t| | |
[ -t[t.first.first][0]["followers_count"].to_i, -t[t.first.first][0]["retweet_count"].to_i, -t[t.first.first][0]["favourites_count"].to_i] | |
end | |
end | |
def remove_reply_tweet(comments) | |
comments.reject{ |c| c["in_reply_to_user_id"].to_i == 42 } | |
end | |
end | |
end |
This file contains hidden or 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
require 'rails_helper' | |
RSpec.describe Twitter::Rules do | |
let(:twitter) { Twitter::WrapperService.new } | |
it "Check sort_followers_retweet_favourites" do | |
default_order = [ | |
{ | |
"followers_count" => 196, | |
"screen_name" => "aaaaa", | |
"retweet_count" => 8, | |
"favorite_count" => 18, | |
"twitter_reply" => false | |
}, | |
{ | |
"followers_count" => 311, | |
"screen_name" => "bbbbb", | |
"retweet_count" => 10, | |
"favorite_count" => 29, | |
"twitter_reply" => false | |
}, | |
{ | |
"followers_count" => 857, | |
"screen_name" => "ccccc", | |
"retweet_count" => 18, | |
"favorite_count" => 40, | |
"twitter_reply" => false | |
} | |
] | |
right_order = [ | |
{ | |
"followers_count" => 857, | |
"screen_name" => "ccccc", | |
"retweet_count" => 18, | |
"favorite_count" => 40, | |
"twitter_reply" => false | |
}, | |
{ | |
"followers_count" => 311, | |
"screen_name" => "bbbbb", | |
"retweet_count" => 10, | |
"favorite_count" => 29, | |
"twitter_reply" => false | |
}, | |
{ | |
"followers_count" => 196, | |
"screen_name" => "aaaaa", | |
"retweet_count" => 8, | |
"favorite_count" => 18, | |
"twitter_reply" => false | |
}, | |
] | |
expect(right_order).to eq(twitter.sort_relevants_followers_retweet_favourites(default_order)) | |
end | |
it "Check sort_mentions_followers_retweet_favourites" do | |
default_order = [ | |
{ | |
"aaaaaaa" => [ | |
{ | |
"followers_count" => 405, | |
"screen_name" => "aaaaaaa", | |
"retweet_count" => 7, | |
"favorite_count" => 12, | |
"twitter_reply" => false | |
} | |
] | |
}, | |
{ | |
"bbbbbbb" => [ | |
{ | |
"followers_count" => 581, | |
"screen_name" => "bbbbbbb", | |
"retweet_count" => 0, | |
"favorite_count" => 47, | |
"twitter_reply" => true | |
} | |
] | |
}, | |
{ | |
"ccccccc" => [ | |
{ | |
"followers_count" => 584, | |
"screen_name" => "ccccccc", | |
"retweet_count" => 0, | |
"favorite_count" => 34, | |
"twitter_reply" => false | |
} | |
] | |
} | |
] | |
right_order = [ | |
{ | |
"ccccccc" => [ | |
{ | |
"followers_count" => 584, | |
"screen_name" => "ccccccc", | |
"retweet_count" => 0, | |
"favorite_count" => 34, | |
"twitter_reply" => false | |
} | |
] | |
}, | |
{ | |
"bbbbbbb" => [ | |
{ | |
"followers_count" => 581, | |
"screen_name" => "bbbbbbb", | |
"retweet_count" => 0, | |
"favorite_count" => 47, | |
"twitter_reply" => true | |
} | |
] | |
}, | |
{ | |
"aaaaaaa" => [ | |
{ | |
"followers_count" => 405, | |
"screen_name" => "aaaaaaa", | |
"retweet_count" => 7, | |
"favorite_count" => 12, | |
"twitter_reply" => false | |
} | |
] | |
} | |
] | |
expect(twitter.sort_mentions_followers_retweet_favourites(default_order)).to eq(right_order) | |
end | |
it "check remove_reply_tweet with in_reply_to_user_id == 42" do | |
default_comments = [ | |
{ | |
"id_str" => "729391", | |
"in_reply_to_user_id_str" => "", | |
"text" => "Try to connect the IB panel, maybe it will c @lalalala ", | |
"retweet_count" => 7, | |
"in_reply_to_status_id_str" => "", | |
"id" => 729391, | |
"retweeted" => true, | |
"in_reply_to_user_id" => "", | |
"favorite_count" => 0, | |
"in_reply_to_status_id" => "" | |
}, | |
{ | |
"id_str" => "242420", | |
"in_reply_to_user_id_str" => "", | |
"text" => "You can't @lalalala without quantifying the mobile!", | |
"retweet_count" => 8, | |
"in_reply_to_status_id_str" => "", | |
"id" => 242420, | |
"geo" => "", | |
"retweeted" => true, | |
"in_reply_to_user_id" => "42", | |
"place" => "", | |
"favorite_count" => 0, | |
"in_reply_to_screen_name" => "", | |
"source" => "web", | |
"in_reply_to_status_id" => "" | |
}, | |
] | |
expect(twitter.remove_reply_tweet(default_comments).size).to eq(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment