git_models 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.dependabot/config.yml +10 -0
  3. data/.github/workflows/gem_release.yml +37 -0
  4. data/.gitignore +61 -0
  5. data/.jenkins/Jenkinsfile +80 -0
  6. data/.jenkins/ruby_build_pod.yml +18 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +51 -0
  9. data/Appraisals +14 -0
  10. data/CHANGELOG.md +25 -0
  11. data/Gemfile +25 -0
  12. data/Gemfile.lock +237 -0
  13. data/README.md +6 -0
  14. data/Rakefile +28 -0
  15. data/app/models/concerns/branch.rb +55 -0
  16. data/app/models/concerns/commit.rb +44 -0
  17. data/app/models/concerns/repository.rb +28 -0
  18. data/app/models/concerns/user.rb +33 -0
  19. data/gemfiles/.bundle/config +2 -0
  20. data/gemfiles/rails_4.gemfile +26 -0
  21. data/gemfiles/rails_5.gemfile +26 -0
  22. data/gemfiles/rails_6.gemfile +26 -0
  23. data/git_models.gemspec +27 -0
  24. data/lib/git_models.rb +6 -0
  25. data/lib/git_models/test_helpers.rb +60 -0
  26. data/lib/git_models/version.rb +5 -0
  27. data/spec/dummy/Rakefile +6 -0
  28. data/spec/dummy/app/assets/config/manifest.js +3 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  30. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  34. data/spec/dummy/app/models/application_record.rb +7 -0
  35. data/spec/dummy/app/models/branch.rb +8 -0
  36. data/spec/dummy/app/models/commit.rb +8 -0
  37. data/spec/dummy/app/models/repository.rb +8 -0
  38. data/spec/dummy/app/models/user.rb +8 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  40. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  41. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  42. data/spec/dummy/bin/bundle +3 -0
  43. data/spec/dummy/bin/rails +4 -0
  44. data/spec/dummy/bin/rake +4 -0
  45. data/spec/dummy/bin/setup +36 -0
  46. data/spec/dummy/bin/spring +16 -0
  47. data/spec/dummy/bin/update +31 -0
  48. data/spec/dummy/bin/yarn +11 -0
  49. data/spec/dummy/config.ru +7 -0
  50. data/spec/dummy/config/application.rb +25 -0
  51. data/spec/dummy/config/boot.rb +5 -0
  52. data/spec/dummy/config/credentials.yml.enc +1 -0
  53. data/spec/dummy/config/database.yml +27 -0
  54. data/spec/dummy/config/environment.rb +8 -0
  55. data/spec/dummy/config/environments/development.rb +63 -0
  56. data/spec/dummy/config/environments/production.rb +96 -0
  57. data/spec/dummy/config/environments/test.rb +55 -0
  58. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  59. data/spec/dummy/config/initializers/assets.rb +16 -0
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
  61. data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  64. data/spec/dummy/config/initializers/inflections.rb +18 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  66. data/spec/dummy/config/initializers/session_store.rb +5 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  68. data/spec/dummy/config/locales/en.yml +33 -0
  69. data/spec/dummy/config/puma.rb +39 -0
  70. data/spec/dummy/config/routes.rb +5 -0
  71. data/spec/dummy/config/spring.rb +8 -0
  72. data/spec/dummy/config/storage.yml +34 -0
  73. data/spec/dummy/db/migrate/20161123065534_create_users_table.rb +16 -0
  74. data/spec/dummy/db/migrate/20161123184217_create_commits_repositories_branches.rb +37 -0
  75. data/spec/dummy/db/schema.rb +53 -0
  76. data/spec/dummy/spec/models/branch_spec.rb +84 -0
  77. data/spec/dummy/spec/models/commit_spec.rb +60 -0
  78. data/spec/dummy/spec/models/user_spec.rb +64 -0
  79. data/spec/dummy/spec/spec_helper.rb +48 -0
  80. metadata +231 -0
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../app/models/commit'
4
+
5
+ RSpec.describe Commit do
6
+ before do
7
+ @git_commit = Git::GitCommit.new(
8
+ '6d8cc7db8021d3dbf90a4ebd378d2ecb97c2bc25',
9
+ 'test message',
10
+ Time.current,
11
+ 'author name',
12
+ 'author@email.com'
13
+ )
14
+ end
15
+
16
+ it 'can create be constructed from a git commit' do
17
+ commit = Commit.create_from_git_commit!(@git_commit)
18
+ expect(commit.sha).to eq('6d8cc7db8021d3dbf90a4ebd378d2ecb97c2bc25')
19
+ expect(commit.message).not_to be_nil
20
+ expect(commit.author.name).not_to be_nil
21
+ expect(commit.author.email).not_to be_nil
22
+ expect(commit.created_at).not_to be_nil
23
+ expect(commit.updated_at).not_to be_nil
24
+ end
25
+
26
+ it 'does not create duplicate database records' do
27
+ Commit.create_from_git_commit!(@git_commit)
28
+ expect(Commit.all.count).to eq(1)
29
+
30
+ Commit.create_from_git_commit!(@git_commit)
31
+ expect(Commit.all.count).to eq(1)
32
+ end
33
+
34
+ it 'rejects shas that are all zeros' do
35
+ git_commit = Git::GitCommit.new(
36
+ '0' * 40,
37
+ 'test message',
38
+ Time.current,
39
+ 'author name',
40
+ 'author@email.com'
41
+ )
42
+
43
+ expect { Commit.create_from_git_commit!(git_commit) }.to \
44
+ raise_exception(ActiveRecord::RecordInvalid)
45
+ end
46
+
47
+ context 'with an existing commit' do
48
+ before do
49
+ @commit = Commit.create_from_git_commit!(@git_commit)
50
+ end
51
+
52
+ it 'prints its sha when stringified' do
53
+ expect(@commit.to_s).to eq('6d8cc7db8021d3dbf90a4ebd378d2ecb97c2bc25')
54
+ end
55
+
56
+ it 'has a short sha' do
57
+ expect(@commit.short_sha).to eq('6d8cc7d')
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../app/models/user'
4
+
5
+ RSpec.describe User do
6
+ it 'can create be constructed from git data' do
7
+ git_data = Git::GitBranch.new(
8
+ 'repository_name',
9
+ 'mypath/mybranch',
10
+ DateTime.current,
11
+ 'Author Name',
12
+ 'author@email.com'
13
+ )
14
+ user = User.create_from_git_data!(git_data)
15
+
16
+ expect(user.name).to eq('Author Name')
17
+ expect(user.email).to eq('author@email.com')
18
+ expect(user.created_at).not_to be_nil
19
+ expect(user.updated_at).not_to be_nil
20
+ end
21
+
22
+ it 'can have multiple branches related to it' do
23
+ GitModels::TestHelpers.create_branches(author_email: 'author@email.com')
24
+ user = User.where(email: 'author@email.com').first
25
+ expect(user.branches.size).to eq(2)
26
+ end
27
+
28
+ it 'can have multiple commits related to it' do
29
+ GitModels::TestHelpers.create_commits(author_email: 'author@email.com')
30
+ user = User.where(email: 'author@email.com').first
31
+ expect(user.commits.size).to eq(2)
32
+ end
33
+
34
+ it 'will not allow duplicate name/email combinations' do
35
+ user1 = User.create(name: 'Author Name', email: 'author@email.com')
36
+ user1.save!
37
+ user2 = User.create(name: 'Author Name', email: 'author@email.com')
38
+
39
+ expect { user2.save! }.to raise_exception(ActiveRecord::RecordInvalid)
40
+ end
41
+
42
+ it 'requires name and email address' do
43
+ expect { User.create(name: 'Author Name') }.to raise_exception(ActiveRecord::StatementInvalid)
44
+ expect { User.create(email: 'author@email.com') }.to raise_exception(ActiveRecord::StatementInvalid)
45
+ end
46
+
47
+ context 'with two users' do
48
+ before do
49
+ @user1 = User.create(name: 'Author Name 1', email: 'email1@email.com')
50
+ @user2 = User.create(name: 'Author Name 2', email: 'email2@email.com')
51
+ end
52
+
53
+ it 'can return list of users filtered by email address' do
54
+ users = User.users_with_emails([])
55
+ expect(users).to eq([@user1, @user2])
56
+
57
+ users = User.users_with_emails([@user1.email])
58
+ expect(users).to eq([@user1])
59
+
60
+ users = User.users_with_emails(['notinlist@email.com'])
61
+ expect(users).to eq([])
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require "bundler/setup"
6
+
7
+ require 'coveralls'
8
+ Coveralls.wear!('rails') if ENV['CI'] == 'true'
9
+ require_relative '../config/environment'
10
+ require 'git/git_test_helpers'
11
+ require 'git_models/test_helpers'
12
+ require 'database_cleaner'
13
+ require 'rake'
14
+ require 'rspec/rails'
15
+ require 'rspec_junit_formatter'
16
+ require 'climate_control'
17
+
18
+ RSpec.configure do |config|
19
+ config.before(:suite) do
20
+ DatabaseCleaner.strategy = :transaction
21
+ ActiveRecord::Migration.maintain_test_schema!
22
+ end
23
+
24
+ config.around(:each) do |example|
25
+ DatabaseCleaner.cleaning do
26
+ example.run
27
+ end
28
+ end
29
+
30
+ config.add_formatter RspecJunitFormatter, ENV['JUNIT_OUTPUT'] || 'spec/reports/rspec.xml'
31
+
32
+ # Enable flags like --only-failures and --next-failure
33
+ config.example_status_persistence_file_path = "spec/reports/.rspec_status"
34
+
35
+ config.expect_with :rspec do |expectations|
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ end
38
+
39
+ config.mock_with :rspec do |mocks|
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ config.shared_context_metadata_behavior = :apply_to_host_groups
44
+
45
+ def with_modified_env(options, &block)
46
+ ClimateControl.modify(options, &block)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_models
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Invoca Development
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: hobo_fields
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: git_lib
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.2'
61
+ description:
62
+ email:
63
+ - development@invoca.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".dependabot/config.yml"
69
+ - ".github/workflows/gem_release.yml"
70
+ - ".gitignore"
71
+ - ".jenkins/Jenkinsfile"
72
+ - ".jenkins/ruby_build_pod.yml"
73
+ - ".rspec"
74
+ - ".rubocop.yml"
75
+ - Appraisals
76
+ - CHANGELOG.md
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - README.md
80
+ - Rakefile
81
+ - app/models/concerns/branch.rb
82
+ - app/models/concerns/commit.rb
83
+ - app/models/concerns/repository.rb
84
+ - app/models/concerns/user.rb
85
+ - gemfiles/.bundle/config
86
+ - gemfiles/rails_4.gemfile
87
+ - gemfiles/rails_5.gemfile
88
+ - gemfiles/rails_6.gemfile
89
+ - git_models.gemspec
90
+ - lib/git_models.rb
91
+ - lib/git_models/test_helpers.rb
92
+ - lib/git_models/version.rb
93
+ - spec/dummy/Rakefile
94
+ - spec/dummy/app/assets/config/manifest.js
95
+ - spec/dummy/app/assets/javascripts/application.js
96
+ - spec/dummy/app/assets/javascripts/cable.js
97
+ - spec/dummy/app/assets/stylesheets/application.css
98
+ - spec/dummy/app/controllers/application_controller.rb
99
+ - spec/dummy/app/helpers/application_helper.rb
100
+ - spec/dummy/app/models/.keep
101
+ - spec/dummy/app/models/application_record.rb
102
+ - spec/dummy/app/models/branch.rb
103
+ - spec/dummy/app/models/commit.rb
104
+ - spec/dummy/app/models/concerns/.keep
105
+ - spec/dummy/app/models/repository.rb
106
+ - spec/dummy/app/models/user.rb
107
+ - spec/dummy/app/views/layouts/application.html.erb
108
+ - spec/dummy/app/views/layouts/mailer.html.erb
109
+ - spec/dummy/app/views/layouts/mailer.text.erb
110
+ - spec/dummy/bin/bundle
111
+ - spec/dummy/bin/rails
112
+ - spec/dummy/bin/rake
113
+ - spec/dummy/bin/setup
114
+ - spec/dummy/bin/spring
115
+ - spec/dummy/bin/update
116
+ - spec/dummy/bin/yarn
117
+ - spec/dummy/config.ru
118
+ - spec/dummy/config/application.rb
119
+ - spec/dummy/config/boot.rb
120
+ - spec/dummy/config/credentials.yml.enc
121
+ - spec/dummy/config/database.yml
122
+ - spec/dummy/config/environment.rb
123
+ - spec/dummy/config/environments/development.rb
124
+ - spec/dummy/config/environments/production.rb
125
+ - spec/dummy/config/environments/test.rb
126
+ - spec/dummy/config/initializers/application_controller_renderer.rb
127
+ - spec/dummy/config/initializers/assets.rb
128
+ - spec/dummy/config/initializers/backtrace_silencers.rb
129
+ - spec/dummy/config/initializers/content_security_policy.rb
130
+ - spec/dummy/config/initializers/cookies_serializer.rb
131
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
132
+ - spec/dummy/config/initializers/inflections.rb
133
+ - spec/dummy/config/initializers/mime_types.rb
134
+ - spec/dummy/config/initializers/session_store.rb
135
+ - spec/dummy/config/initializers/wrap_parameters.rb
136
+ - spec/dummy/config/locales/en.yml
137
+ - spec/dummy/config/puma.rb
138
+ - spec/dummy/config/routes.rb
139
+ - spec/dummy/config/spring.rb
140
+ - spec/dummy/config/storage.yml
141
+ - spec/dummy/db/migrate/20161123065534_create_users_table.rb
142
+ - spec/dummy/db/migrate/20161123184217_create_commits_repositories_branches.rb
143
+ - spec/dummy/db/schema.rb
144
+ - spec/dummy/lib/assets/.keep
145
+ - spec/dummy/lib/tasks/.keep
146
+ - spec/dummy/spec/models/branch_spec.rb
147
+ - spec/dummy/spec/models/commit_spec.rb
148
+ - spec/dummy/spec/models/user_spec.rb
149
+ - spec/dummy/spec/spec_helper.rb
150
+ homepage: https://github.com/Invoca/git_models
151
+ licenses: []
152
+ metadata:
153
+ allowed_push_host: https://rubygems.org
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - app
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.0.1
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Rails models for Git data.
174
+ test_files:
175
+ - spec/dummy/Rakefile
176
+ - spec/dummy/app/assets/config/manifest.js
177
+ - spec/dummy/app/assets/javascripts/application.js
178
+ - spec/dummy/app/assets/javascripts/cable.js
179
+ - spec/dummy/app/assets/stylesheets/application.css
180
+ - spec/dummy/app/controllers/application_controller.rb
181
+ - spec/dummy/app/helpers/application_helper.rb
182
+ - spec/dummy/app/models/.keep
183
+ - spec/dummy/app/models/application_record.rb
184
+ - spec/dummy/app/models/branch.rb
185
+ - spec/dummy/app/models/commit.rb
186
+ - spec/dummy/app/models/concerns/.keep
187
+ - spec/dummy/app/models/repository.rb
188
+ - spec/dummy/app/models/user.rb
189
+ - spec/dummy/app/views/layouts/application.html.erb
190
+ - spec/dummy/app/views/layouts/mailer.html.erb
191
+ - spec/dummy/app/views/layouts/mailer.text.erb
192
+ - spec/dummy/bin/bundle
193
+ - spec/dummy/bin/rails
194
+ - spec/dummy/bin/rake
195
+ - spec/dummy/bin/setup
196
+ - spec/dummy/bin/spring
197
+ - spec/dummy/bin/update
198
+ - spec/dummy/bin/yarn
199
+ - spec/dummy/config.ru
200
+ - spec/dummy/config/application.rb
201
+ - spec/dummy/config/boot.rb
202
+ - spec/dummy/config/credentials.yml.enc
203
+ - spec/dummy/config/database.yml
204
+ - spec/dummy/config/environment.rb
205
+ - spec/dummy/config/environments/development.rb
206
+ - spec/dummy/config/environments/production.rb
207
+ - spec/dummy/config/environments/test.rb
208
+ - spec/dummy/config/initializers/application_controller_renderer.rb
209
+ - spec/dummy/config/initializers/assets.rb
210
+ - spec/dummy/config/initializers/backtrace_silencers.rb
211
+ - spec/dummy/config/initializers/content_security_policy.rb
212
+ - spec/dummy/config/initializers/cookies_serializer.rb
213
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
214
+ - spec/dummy/config/initializers/inflections.rb
215
+ - spec/dummy/config/initializers/mime_types.rb
216
+ - spec/dummy/config/initializers/session_store.rb
217
+ - spec/dummy/config/initializers/wrap_parameters.rb
218
+ - spec/dummy/config/locales/en.yml
219
+ - spec/dummy/config/puma.rb
220
+ - spec/dummy/config/routes.rb
221
+ - spec/dummy/config/spring.rb
222
+ - spec/dummy/config/storage.yml
223
+ - spec/dummy/db/migrate/20161123065534_create_users_table.rb
224
+ - spec/dummy/db/migrate/20161123184217_create_commits_repositories_branches.rb
225
+ - spec/dummy/db/schema.rb
226
+ - spec/dummy/lib/assets/.keep
227
+ - spec/dummy/lib/tasks/.keep
228
+ - spec/dummy/spec/models/branch_spec.rb
229
+ - spec/dummy/spec/models/commit_spec.rb
230
+ - spec/dummy/spec/models/user_spec.rb
231
+ - spec/dummy/spec/spec_helper.rb