@@ -7,34 +7,56 @@ class CommitsRunnerTest < ActiveSupport::TestCase
77 @repo = create ( :repo , name : 'rails' )
88 end
99
10- test '#run' do
10+ test '#run commits triggered by webhook ' do
1111 commits = [
1212 {
13- sha : '12345' ,
14- message : 'My beautiful commit message' ,
15- repo : @repo ,
16- author_name : 'bmarkons' ,
17- url : 'https://github.com/commit' ,
18- created_at : 12345
13+ 'id' => '12345' ,
14+ 'message' => 'My beautiful commit message' ,
15+ 'author' => {
16+ 'name' => 'bmarkons'
17+ } ,
18+ 'url' => 'https://github.com/commit' ,
19+ 'timestamp' => 12345
1920 }
2021 ]
2122
22- CommitsRunner . run ( commits )
23+ CommitsRunner . run ( :webhook , commits , @repo )
2324
2425 expect_created ( commits )
2526 assert_enqueued_jobs ( commits . count )
2627 end
2728
28- def expect_created ( commits_hashes )
29- commits_hashes . each do |hash |
30- commit = Commit . find_by! ( sha1 : hash [ :sha ] )
29+ test '#run commits triggered manually' do
30+ commits = [
31+ {
32+ 'sha' => '12345' ,
33+ 'commit' => {
34+ 'message' => 'My beautiful commit message' ,
35+ 'author' => {
36+ 'date' => 12345 ,
37+ 'name' => 'bmarkons'
38+ }
39+ } ,
40+ 'html_url' => 'https://github.com/commit'
41+ }
42+ ]
43+
44+ CommitsRunner . run ( :api , commits , @repo )
45+
46+ expect_created ( commits )
47+ assert_enqueued_jobs ( commits . count )
48+ end
49+
50+ def expect_created ( commit_hashes )
51+ commit_hashes . each do |commit_hash |
52+ commit = Commit . find_by! ( sha1 : commit_hash [ 'sha' ] || commit_hash [ 'id' ] )
3153
32- assert_equal hash [ : sha] , commit . sha1
33- assert_equal hash [ : message] , commit . message
34- assert_equal hash [ : repo] . id , commit . repo . id
35- assert_equal hash [ : repo] . name , commit . repo . name
36- assert_equal hash [ : url] , commit . url
37- refute_equal hash [ :created_at ] , commit . created_at
54+ assert_equal commit_hash [ 'id' ] || commit_hash [ ' sha' ] , commit . sha1
55+ assert_equal commit_hash [ ' message' ] || commit_hash [ 'commit' ] [ 'message' ] , commit . message
56+ assert_equal @ repo. id , commit . repo . id
57+ assert_equal @ repo. name , commit . repo . name
58+ assert_equal commit_hash [ ' url' ] || commit_hash [ 'html_url' ] , commit . url
59+ refute_equal commit_hash [ 'timestamp' ] || commit_hash [ 'commit' ] [ 'author' ] [ 'date' ] , commit . created_at
3860 end
3961 end
4062end
0 commit comments