introspective_grape 0.5.7 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +22 -18
  3. data/README.md +2 -0
  4. data/introspective_grape.gemspec +5 -4
  5. data/lib/introspective_grape/api.rb +461 -459
  6. data/lib/introspective_grape/create_helpers.rb +25 -25
  7. data/lib/introspective_grape/traversal.rb +1 -1
  8. data/lib/introspective_grape/validators.rb +36 -36
  9. data/lib/introspective_grape/version.rb +5 -5
  10. data/spec/dummy/Gemfile +23 -22
  11. data/spec/dummy/app/api/api_helpers.rb +38 -37
  12. data/spec/dummy/app/api/dummy_api.rb +61 -61
  13. data/spec/dummy/app/api/permissions_helper.rb +7 -7
  14. data/spec/dummy/app/helpers/current.rb +3 -0
  15. data/spec/dummy/app/models/chat_message.rb +34 -34
  16. data/spec/dummy/app/models/chat_user.rb +16 -16
  17. data/spec/dummy/app/models/location.rb +26 -26
  18. data/spec/dummy/app/models/role.rb +30 -30
  19. data/spec/dummy/app/models/team.rb +14 -9
  20. data/spec/dummy/app/models/user/chatter.rb +79 -79
  21. data/spec/dummy/bin/bundle +3 -3
  22. data/spec/dummy/bin/rails +4 -4
  23. data/spec/dummy/bin/setup +36 -29
  24. data/spec/dummy/bin/update +31 -0
  25. data/spec/dummy/bin/yarn +11 -0
  26. data/spec/dummy/config/application.rb +30 -37
  27. data/spec/dummy/config/boot.rb +3 -6
  28. data/spec/dummy/config/environment.rb +5 -11
  29. data/spec/dummy/config/environments/development.rb +54 -42
  30. data/spec/dummy/config/environments/production.rb +81 -79
  31. data/spec/dummy/config/environments/test.rb +47 -44
  32. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  33. data/spec/dummy/config/initializers/assets.rb +14 -11
  34. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  35. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -3
  36. data/spec/dummy/config/initializers/inflections.rb +16 -16
  37. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
  38. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  39. data/spec/dummy/config/locales/en.yml +33 -23
  40. data/spec/dummy/config/storage.yml +34 -0
  41. data/spec/models/image_spec.rb +10 -14
  42. data/spec/requests/project_api_spec.rb +185 -182
  43. data/spec/requests/user_api_spec.rb +221 -221
  44. data/spec/support/request_helpers.rb +22 -21
  45. metadata +20 -157
@@ -1,79 +1,79 @@
1
- module User::Chatter
2
-
3
- def message_query(chat_id, new = true)
4
- messages.joins(:chat_message_users)
5
- .where('chat_message_users.user_id'=> id)
6
- .where(new ? {'chat_message_users.read_at'=>nil} : '')
7
- .where(chat_id ? {'chat_messages.chat_id'=> chat_id} : '')
8
- .order('') # or it will add an order by id clause that breaks the count query.
9
- end
10
-
11
- def new_messages?(chat=nil) # returns a hash of chat_ids with new message counts
12
- chat_id = chat.kind_of?(Chat) ? chat.id : chat
13
- new = message_query(chat_id)
14
- .select("chat_messages.chat_id, count(chat_messages.id) as count")
15
- .group('chat_id')
16
-
17
- chat ? { chat_id => new.first.try(:count)||0 } : Hash[new.map {|c| [c.chat_id, c.count]} ]
18
- end
19
-
20
- def read_messages(chat= nil, mark_as_read= false, new= true)
21
- chat_id = chat.kind_of?(Chat) ? chat.id : chat
22
- new = message_query(chat_id, new).order('chat_messages.created_at').includes(:author) # :chat?
23
- new.map(&:chat).uniq.each {|c| mark_as_read(c) } if mark_as_read
24
- new
25
- end
26
-
27
- def chat(users, message)
28
- users = [users].flatten
29
- users = users.first.kind_of?(User) ? users : User.where(id: users)
30
- chat = Chat.create(creator: self)
31
- chat.users.push users
32
- chat.messages.build(message: message, author: self)
33
- chat.save!
34
- chat
35
- end
36
-
37
- def reply(chat, message)
38
- chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
39
- mark_as_read(chat) # a reply implies that the thread has been read
40
- chat.messages.build(message: message, author: self)
41
- chat.save!
42
- chat
43
- end
44
-
45
- def add_chatters(chat, users)
46
- users = [users].flatten
47
- users = users.first.kind_of?(User) ? users : User.where(id: users)
48
- chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
49
-
50
- if chat.active_users.include?(self) # only current participants can add new users
51
- chat.users.push users
52
- chat.messages.build(chat: chat, author: self, message: "#{self.name} [[ADDED_USER_MESSAGE]] #{users.map(&:name).join(',')}")
53
- chat.save!
54
- else
55
- chat.errors[:base] << "Only current chat participants can add users."
56
- raise ActiveRecord::RecordInvalid.new(chat)
57
- end
58
- end
59
-
60
- def leave_chat(chat)
61
- chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
62
-
63
- if chat.active_users.include?(self)
64
- reply(chat, "#{name} [[DEPARTS_MESSAGE]]")
65
- chat.chat_users.detect {|cu| cu.user_id == self.id}.update_attributes(departed_at: Time.now)
66
- else
67
- true
68
- end
69
- end
70
-
71
- def mark_as_read(chat)
72
- ChatMessageUser.joins(:chat_message).where('read_at IS NULL AND chat_messages.chat_id = ? AND user_id = ?', chat.id, id).update_all(read_at: Time.now)
73
- end
74
-
75
- def mark_messages_as_read(messages)
76
- chat_message_users.where("chat_message_id in (?) and read_at IS NULL", messages.map(&:id)).update_all(read_at: Time.now)
77
- end
78
-
79
- end
1
+ module User::Chatter
2
+
3
+ def message_query(chat_id, new = true)
4
+ messages.joins(:chat_message_users)
5
+ .where('chat_message_users.user_id'=> id)
6
+ .where(new ? {'chat_message_users.read_at'=>nil} : '')
7
+ .where(chat_id ? {'chat_messages.chat_id'=> chat_id} : '')
8
+ .order('') # or it will add an order by id clause that breaks the count query.
9
+ end
10
+
11
+ def new_messages?(chat=nil) # returns a hash of chat_ids with new message counts
12
+ chat_id = chat.kind_of?(Chat) ? chat.id : chat
13
+ new = message_query(chat_id)
14
+ .select("chat_messages.chat_id, count(chat_messages.id) as count")
15
+ .group('chat_id')
16
+
17
+ chat ? { chat_id => new.first.try(:count)||0 } : Hash[new.map {|c| [c.chat_id, c.count]} ]
18
+ end
19
+
20
+ def read_messages(chat= nil, mark_as_read= false, new= true)
21
+ chat_id = chat.kind_of?(Chat) ? chat.id : chat
22
+ new = message_query(chat_id, new).order('chat_messages.created_at').includes(:author) # :chat?
23
+ new.map(&:chat).uniq.each {|c| mark_as_read(c) } if mark_as_read
24
+ new
25
+ end
26
+
27
+ def chat(users, message)
28
+ users = [users].flatten
29
+ users = users.first.kind_of?(User) ? users : User.where(id: users)
30
+ chat = Chat.create(creator: self)
31
+ chat.users.push users
32
+ chat.messages.build(message: message, author: self)
33
+ chat.save!
34
+ chat
35
+ end
36
+
37
+ def reply(chat, message)
38
+ chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
39
+ mark_as_read(chat) # a reply implies that the thread has been read
40
+ chat.messages.build(message: message, author: self)
41
+ chat.save!
42
+ chat
43
+ end
44
+
45
+ def add_chatters(chat, users)
46
+ users = [users].flatten
47
+ users = users.first.kind_of?(User) ? users : User.where(id: users)
48
+ chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
49
+
50
+ if chat.active_users.include?(self) # only current participants can add new users
51
+ chat.users.push users
52
+ chat.messages.build(chat: chat, author: self, message: "#{self.name} [[ADDED_USER_MESSAGE]] #{users.map(&:name).join(',')}")
53
+ chat.save!
54
+ else
55
+ chat.errors.add(:base, "Only current chat participants can add users.")
56
+ raise ActiveRecord::RecordInvalid.new(chat)
57
+ end
58
+ end
59
+
60
+ def leave_chat(chat)
61
+ chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
62
+
63
+ if chat.active_users.include?(self)
64
+ reply(chat, "#{name} [[DEPARTS_MESSAGE]]")
65
+ chat.chat_users.detect {|cu| cu.user_id == self.id}.update(departed_at: Time.now)
66
+ else
67
+ true
68
+ end
69
+ end
70
+
71
+ def mark_as_read(chat)
72
+ ChatMessageUser.joins(:chat_message).where('read_at IS NULL AND chat_messages.chat_id = ? AND user_id = ?', chat.id, id).update_all(read_at: Time.now)
73
+ end
74
+
75
+ def mark_messages_as_read(messages)
76
+ chat_message_users.where("chat_message_id in (?) and read_at IS NULL", messages.map(&:id)).update_all(read_at: Time.now)
77
+ end
78
+
79
+ end
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
data/spec/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
data/spec/dummy/bin/setup CHANGED
@@ -1,29 +1,36 @@
1
- #!/usr/bin/env ruby
2
- require 'pathname'
3
-
4
- # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
-
7
- Dir.chdir APP_ROOT do
8
- # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
10
-
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
14
-
15
- # puts "\n== Copying sample files =="
16
- # unless File.exist?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
18
- # end
19
-
20
- puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
22
-
23
- puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
26
-
27
- puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
29
- end
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:setup'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path('..', __dir__)
3
+ Dir.chdir(APP_ROOT) do
4
+ begin
5
+ exec "yarnpkg", *ARGV
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -1,37 +1,30 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- # Pick the frameworks you want:
4
- require "active_record/railtie"
5
- require "action_controller/railtie"
6
- require "action_mailer/railtie"
7
- require "action_view/railtie"
8
- require "sprockets/railtie"
9
- require 'devise'
10
- #require 'devise/async'
11
- require 'grape-swagger'
12
- require 'grape-entity'
13
- # require "rails/test_unit/railtie"
14
-
15
- #Bundler.require(*Rails.groups)
16
- require "introspective_grape"
17
- require 'introspective_grape/camel_snake'
18
-
19
- module Dummy
20
- class Application < Rails::Application
21
- # Settings in config/environments/* take precedence over those specified here.
22
- # Application configuration should go into files in config/initializers
23
- # -- all .rb files in that directory are automatically loaded.
24
-
25
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
- # config.time_zone = 'Central Time (US & Canada)'
28
-
29
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
- # config.i18n.default_locale = :de
32
-
33
- # Do not swallow errors in after_commit/after_rollback callbacks.
34
- #config.active_record.raise_in_transactional_callbacks = true
35
-
36
- end
37
- end
1
+ require_relative 'boot'
2
+
3
+ require "rails"
4
+ # Pick the frameworks you want:
5
+ require "active_model/railtie"
6
+ require "active_job/railtie"
7
+ require "active_record/railtie"
8
+ require "active_storage/engine"
9
+ require "action_controller/railtie"
10
+ require "action_mailer/railtie"
11
+ require "action_view/railtie"
12
+ # require "action_cable/engine"
13
+ # require "sprockets/railtie"
14
+ require "rails/test_unit/railtie"
15
+
16
+ # Require the gems listed in Gemfile, including any gems
17
+ # you've limited to :test, :development, or :production.
18
+ Bundler.require(*Rails.groups)
19
+
20
+ module Dummy
21
+ class Application < Rails::Application
22
+ # Initialize configuration defaults for originally generated Rails version.
23
+ #config.load_defaults 7.0
24
+
25
+ # Settings in config/environments/* take precedence over those specified here.
26
+ # Application configuration can go into files in config/initializers
27
+ # -- all .rb files in that directory are automatically loaded after loading
28
+ # the framework and any gems in your application.
29
+ end
30
+ end
@@ -1,6 +1,3 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
6
-
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -1,11 +1,5 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Rails.application.initialize!
6
- #load "#{Rails.root}/db/schema.rb"
7
-
8
-
9
- #Dir[Rails.root.join("app/api/**/*.rb")].each { |f| require f }
10
- Rails.application.reload_routes!
11
-
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -1,42 +1,54 @@
1
- Rails.application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Do not eager load code on boot.
10
- config.eager_load = false
11
-
12
- # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send.
17
- config.action_mailer.raise_delivery_errors = false
18
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
19
-
20
- # Print deprecation notices to the Rails logger.
21
- config.active_support.deprecation = :log
22
-
23
- # Raise an error on page load if there are pending migrations.
24
- config.active_record.migration_error = :page_load
25
-
26
- # Debug mode disables concatenation and preprocessing of assets.
27
- # This option may cause significant delays in view rendering with a large
28
- # number of complex assets.
29
- #config.assets.debug = true
30
-
31
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
32
- # yet still be able to expire them through the digest params.
33
- #config.assets.digest = true
34
-
35
- # Adds additional error checking when serving assets at runtime.
36
- # Checks for improperly declared sprockets dependencies.
37
- # Raises helpful error messages.
38
- #config.assets.raise_runtime_errors = true
39
-
40
- # Raises error for missing translations
41
- # config.action_view.raise_on_missing_translations = true
42
- end
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ # Run rails dev:cache to toggle caching.
17
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
18
+ config.action_controller.perform_caching = true
19
+
20
+ config.cache_store = :memory_store
21
+ config.public_file_server.headers = {
22
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23
+ }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+
27
+ config.cache_store = :null_store
28
+ end
29
+
30
+ # Store uploaded files on the local file system (see config/storage.yml for options)
31
+ config.active_storage.service = :local
32
+
33
+ # Don't care if the mailer can't send.
34
+ config.action_mailer.raise_delivery_errors = false
35
+ config.action_mailer.default_url_options = { :host => "yourhost.com" }
36
+ config.action_mailer.perform_caching = false
37
+
38
+ # Print deprecation notices to the Rails logger.
39
+ config.active_support.deprecation = :log
40
+
41
+ # Raise an error on page load if there are pending migrations.
42
+ config.active_record.migration_error = :page_load
43
+
44
+ # Highlight code that triggered database queries in logs.
45
+ config.active_record.verbose_query_logs = true
46
+
47
+
48
+ # Raises error for missing translations
49
+ # config.action_view.raise_on_missing_translations = true
50
+
51
+ # Use an evented file watcher to asynchronously detect changes in source code,
52
+ # routes, locales, etc. This feature depends on the listen gem.
53
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
54
+ end