Skip to content

Commit 8756bfa

Browse files
Merge pull request #14 from datacite/create-event-model
create event model
2 parents 0f436f2 + 518c659 commit 8756bfa

File tree

11 files changed

+72
-5
lines changed

11 files changed

+72
-5
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins:
55
- rubocop-performance
66
- rubocop-rails
77
- rubocop-rspec
8+
- rubocop-rspec_rails
89

910
require:
1011
- rubocop-factory_bot

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ COPY vendor/docker/10_ssh.sh /etc/my_init.d/10_ssh.sh
6464
# COPY vendor/docker/80_flush_cache.sh /etc/my_init.d/80_flush_cache.sh
6565
COPY vendor/docker/90_migrate.sh /etc/my_init.d/90_migrate.sh
6666

67+
# Add the directory to the list of safe directories
68+
RUN git config --global --add safe.directory /home/app/webapp
69+
6770
# Expose web
6871
EXPOSE 80

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ group :development, :test do
3333
gem "rubocop-performance", require: false
3434
gem "rubocop-factory_bot", require: false
3535
gem "rubocop-rails", require: false
36+
gem "rubocop-rspec_rails", require: false
3637
gem "factory_bot_rails", require: false
3738
gem "bundler-audit", require: false
3839
gem "brakeman", require: false

Gemfile.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ GEM
308308
rubocop-rspec (3.5.0)
309309
lint_roller (~> 1.1)
310310
rubocop (~> 1.72, >= 1.72.1)
311+
rubocop-rspec_rails (2.31.0)
312+
lint_roller (~> 1.1)
313+
rubocop (~> 1.72, >= 1.72.1)
314+
rubocop-rspec (~> 3.5)
311315
rubocop-shopify (2.16.0)
312316
rubocop (~> 1.62)
313317
ruby-progressbar (1.13.0)
@@ -368,6 +372,7 @@ DEPENDENCIES
368372
rubocop-performance
369373
rubocop-rails
370374
rubocop-rspec
375+
rubocop-rspec_rails
371376
rubocop-shopify
372377
sentry-rails
373378
sentry-ruby
@@ -377,4 +382,4 @@ RUBY VERSION
377382
ruby 3.1.6p260
378383

379384
BUNDLED WITH
380-
2.5.6
385+
2.5.6

app/controllers/events_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
class EventsController < ApplicationController
44
def index
5-
Sentry.capture_message("events_controller test message")
6-
render(json: { message: "index" })
5+
attributes = {
6+
id: 1,
7+
uuid: "new_uuid",
8+
created_at: Time.now.utc,
9+
}
10+
event = Event.new(attributes)
11+
render(json: { data: event })
712
end
813

914
def create

app/models/event.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,39 @@ class Event < ApplicationRecord
44
# include Modelable
55
# include Identifiable
66
# include Elasticsearch::Model
7+
8+
# Attributes
9+
attribute :uuid, :text
10+
attribute :subj_id, :text
11+
attribute :obj_id, :text
12+
attribute :source_id, :string
13+
attribute :aasm_state, :string # could we remove this
14+
attribute :state_event, :string # could we remove this
15+
attribute :callback, :text
16+
attribute :error_messages, :text
17+
attribute :source_token, :text
18+
attribute :created_at, :datetime
19+
attribute :updated_at, :datetime
20+
attribute :indexed_at, :datetime, default: -> { Time.zone.at(0) }
21+
attribute :occurred_at, :datetime
22+
attribute :message_action, :string, default: "create" # how is this set?
23+
attribute :subj, :text
24+
attribute :obj, :text
25+
attribute :total, :integer, default: 1
26+
attribute :license, :string
27+
attribute :source_doi, :text
28+
attribute :target_doi, :text
29+
attribute :source_relation_type_id, :string
30+
attribute :target_relation_type_id, :string
31+
32+
# Validations
33+
validates :uuid, presence: true, uniqueness: {
34+
case_sensitive: false,
35+
length: { maximum: 36 },
36+
}
37+
validates :subj_id, presence: true
38+
validates :message_action, presence: true, length: { maximum: 191 }
39+
validates :created_at, presence: true
40+
validates :updated_at, presence: true
41+
validates :indexed_at, presence: true
742
end

config/application.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class Application < Rails::Application
2727

2828
config.autoload_lib(ignore: nil)
2929

30+
# Autoload paths
31+
# You typically add directories to autoload_paths so that classes and modules are loaded
32+
# automatically as they are referenced. This makes development more convenient
33+
# config.autoload_paths << "#{config.root}/app/models/factories"
34+
35+
# Eager load paths
36+
# You typically add directories to eager_load_paths to ensure that all necessary classes
37+
# and modules are loaded at startup, improving performance in production.
38+
# config.eager_load_paths << "#{config.root}/app/models/factories"
39+
3040
config.api_only = true
3141

3242
config.middleware.use(Rack::Deflater)

config/initializers/sentry.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
config.enabled_environments = ["stage", "production"]
55
config.dsn = ENV["SENTRY_DSN"]
66
config.release = "events:" + Events::Application::VERSION
7-
# config.logger = Rails.application.config.lograge.logger
87
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
98
config.send_default_pii = true
109

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ services:
2424
- ./tmp:/home/app/webapp/tmp
2525
- bundle_cache:/home/app/webapp/vendor/bundle
2626
- ./Gemfile:/home/app/webapp/Gemfile
27+
- ./Gemfile.lock:/home/app/webapp/Gemfile.lock
2728
dns:
2829
- 10.0.2.20
2930
networks:

spec/models/event_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe(Event, type: :model) do
6+
pending "add some examples to (or delete) #{__FILE__}"
7+
end

0 commit comments

Comments
 (0)