introspective_grape 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module IntrospectiveGrape
2
2
  module CreateHelpers
3
3
 
4
4
  def add_new_records_to_root_record(dsl, routes, params, model)
5
- dsl.authorize model, :create?
5
+ dsl.send(:authorize, model, :create?)
6
6
  ActiveRecord::Base.transaction do
7
7
  old = find_leaves(routes, model, params)
8
8
  model.update_attributes( dsl.send(:safe_params,params).permit(whitelist) )
@@ -13,7 +13,7 @@ module IntrospectiveGrape
13
13
 
14
14
  def create_new_record(dsl, routes, params)
15
15
  model = routes.first.model.new( dsl.send(:safe_params,params).permit(whitelist) )
16
- dsl.authorize model, :create?
16
+ dsl.send(:authorize, model, :create?)
17
17
  model.save!
18
18
 
19
19
  # reload the model with eager loading
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.3.5".freeze
2
+ VERSION = "0.3.6".freeze
3
3
  end
@@ -1,18 +1,20 @@
1
1
  source 'https://rubygems.org'
2
- gem 'rails', '<5.0'
2
+ gem 'rails'
3
3
 
4
4
  #gem 'byebug'
5
- #gem 'camel_snake_keys'
5
+ gem 'camel_snake_keys'
6
6
 
7
+ gem 'devise'
7
8
  gem 'delayed_paperclip'
8
9
  #gem 'devise-async'
9
10
 
10
11
  gem 'grape'
11
12
  gem 'grape-entity'
12
- gem 'grape-kaminari'
13
+ gem 'grape-kaminari', '<1.8.0'
13
14
  gem 'grape-swagger'
15
+ gem 'introspective_grape', git: 'https://github.com/buermann/introspective_grape', branch: 'rails.5'
14
16
 
15
17
  gem 'paperclip'
16
18
  gem 'pundit'
17
19
 
18
- gem 'sqlite3'
20
+ gem 'sqlite3', '< 1.4.0'
@@ -2,7 +2,7 @@ class Role < AbstractAdapter
2
2
  belongs_to :user
3
3
  belongs_to :ownable, polymorphic: true
4
4
 
5
- validates_uniqueness_of :user_id, scope: [:ownable_type,:ownable_id], unless: "user_id.nil?", message: "user has already been assigned that role"
5
+ validates_uniqueness_of :user_id, scope: [:ownable_type,:ownable_id], unless: Proc.new {|u| u.user_id.nil? }, message: "user has already been assigned that role"
6
6
  OWNABLE_TYPES = %w(Company Project).freeze
7
7
  validates_inclusion_of :ownable_type, in: OWNABLE_TYPES
8
8
 
@@ -33,8 +33,8 @@ class User < AbstractAdapter
33
33
 
34
34
  has_many :roles, dependent: :destroy, inverse_of: :user
35
35
  accepts_nested_attributes_for :roles, allow_destroy: true
36
- has_many :admin_companies, through: :roles, source: :ownable, source_type: Company
37
- has_many :admin_projects, through: :roles, source: :ownable, source_type: Project
36
+ has_many :admin_companies, through: :roles, source: :ownable, source_type: 'Company'
37
+ has_many :admin_projects, through: :roles, source: :ownable, source_type: 'Project'
38
38
 
39
39
  def all_admin_projects # aggregate companies' projects with project admin roles
40
40
  (admin_companies.map(&:projects)+admin_projects).flatten
@@ -5,7 +5,7 @@ require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_mailer/railtie"
7
7
  require "action_view/railtie"
8
- #require "sprockets/railtie"
8
+ require "sprockets/railtie"
9
9
  require 'devise'
10
10
  #require 'devise/async'
11
11
  require 'grape-swagger'
@@ -26,16 +26,16 @@ Rails.application.configure do
26
26
  # Debug mode disables concatenation and preprocessing of assets.
27
27
  # This option may cause significant delays in view rendering with a large
28
28
  # number of complex assets.
29
- config.assets.debug = true
29
+ #config.assets.debug = true
30
30
 
31
31
  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
32
32
  # yet still be able to expire them through the digest params.
33
- config.assets.digest = true
33
+ #config.assets.digest = true
34
34
 
35
35
  # Adds additional error checking when serving assets at runtime.
36
36
  # Checks for improperly declared sprockets dependencies.
37
37
  # Raises helpful error messages.
38
- config.assets.raise_runtime_errors = true
38
+ #config.assets.raise_runtime_errors = true
39
39
 
40
40
  # Raises error for missing translations
41
41
  # config.action_view.raise_on_missing_translations = true
@@ -1,6 +1,6 @@
1
1
  module Paperclip
2
2
  class HashUploadedFileAdapter < AbstractAdapter
3
- def initialize(target)
3
+ def initialize(target, args)
4
4
  @tempfile, @content_type, @size = target['tempfile'], target['type'], target['tempfile'].size
5
5
  @original_filename = target['filename']
6
6
  end
@@ -31,7 +31,7 @@ describe Dummy::ChatAPI, type: :request do
31
31
 
32
32
  it "should return a list of a user's chats" do
33
33
  get "/api/v1/chats"
34
- response.should be_success
34
+ response.should be_successful
35
35
  json.size.should == 2
36
36
  json.first['creator_id'].to_i.should == @sender.id
37
37
  json.first['users'].size.should == Chat.find(json.first['id']).users.size
@@ -40,20 +40,20 @@ describe Dummy::ChatAPI, type: :request do
40
40
  context :notifications do
41
41
  it "should get new chat notifications" do
42
42
  get "/api/v1/chats/notifications/"
43
- response.should be_success
43
+ response.should be_successful
44
44
  json.keys.size.should == 1
45
45
  json[@pm.id.to_s].should == 3
46
46
  end
47
47
 
48
48
  it "should get new chat notifications for a particular chat" do
49
- get "/api/v1/chats/notifications/", id: @pm.id
50
- response.should be_success
49
+ get "/api/v1/chats/notifications/", params: { id: @pm.id }
50
+ response.should be_successful
51
51
  json[@pm.id.to_s].should == 3
52
52
  end
53
53
 
54
54
  it "should return 0 for non-existent chats" do
55
- get "/api/v1/chats/notifications/", id: 0
56
- response.should be_success
55
+ get "/api/v1/chats/notifications/", params: { id: 0 }
56
+ response.should be_successful
57
57
  json['0'].should == 0
58
58
  end
59
59
  end
@@ -61,23 +61,23 @@ describe Dummy::ChatAPI, type: :request do
61
61
  context :messages do
62
62
 
63
63
  it "should get no new chat messages if user was last to reply" do
64
- get "/api/v1/chats/messages", id: @chat.id, new: true
65
- response.should be_success
64
+ get "/api/v1/chats/messages", params: { id: @chat.id, new: true }
65
+ response.should be_successful
66
66
  json.size.should == 0
67
67
  end
68
68
 
69
69
  it "should get new chat messages if user recieves another reply" do
70
70
  @sender.reply(@chat, "And now for something completely different.")
71
- get "/api/v1/chats/messages", id: @chat.id, new: true
72
- response.should be_success
71
+ get "/api/v1/chats/messages", params: { id: @chat.id, new: true }
72
+ response.should be_successful
73
73
  json.size.should == 1
74
74
  end
75
75
 
76
76
  it "should mark all new messages from all chats as read if mark_as_read is true" do
77
77
  @sender.reply(@chat, 'A new response.')
78
78
  @current_user.new_messages?.keys.size.should == 2
79
- get "/api/v1/chats/messages", new: true, mark_as_read: true
80
- response.should be_success
79
+ get "/api/v1/chats/messages", params: { new: true, mark_as_read: true }
80
+ response.should be_successful
81
81
  json.size.should == 4
82
82
  @current_user.new_messages?.keys.size.should == 0
83
83
  end
@@ -86,8 +86,8 @@ describe Dummy::ChatAPI, type: :request do
86
86
 
87
87
  context :users do
88
88
  it "should list the users in a chat" do
89
- get "/api/v1/chats/users", id: @chat.id
90
- response.should be_success
89
+ get "/api/v1/chats/users", params: { id: @chat.id }
90
+ response.should be_successful
91
91
  json.size.should == 3
92
92
  json.map{|u| u['email']}.sort.should == [ "current_user@springshot.com", "lurker@springshot.com", "sender@springshot.com" ]
93
93
  end
@@ -95,8 +95,8 @@ describe Dummy::ChatAPI, type: :request do
95
95
  it "should add a new user to a chat" do
96
96
  new_user1 = User.make
97
97
  new_user1.save!
98
- post "/api/v1/chats/users", id: @chat.id, user_ids: new_user1.id
99
- response.should be_success
98
+ post "/api/v1/chats/users", params: { id: @chat.id, user_ids: new_user1.id }
99
+ response.should be_successful
100
100
  json['status'].should == true
101
101
  @chat.reload
102
102
  @chat.active_users.include?(new_user1).should == true
@@ -107,8 +107,8 @@ describe Dummy::ChatAPI, type: :request do
107
107
  new_user2 = User.make
108
108
  new_user1.save!
109
109
  new_user2.save!
110
- post "/api/v1/chats/users", id: @chat.id, user_ids: "#{new_user1.id},#{new_user2.id}"
111
- response.should be_success
110
+ post "/api/v1/chats/users", params: { id: @chat.id, user_ids: "#{new_user1.id},#{new_user2.id}" }
111
+ response.should be_successful
112
112
  json['status'].should == true
113
113
  @chat.reload
114
114
  @chat.active_users.include?(new_user1).should == true
@@ -117,7 +117,7 @@ describe Dummy::ChatAPI, type: :request do
117
117
 
118
118
  it "should be invalid to add an already active chat member to a chat" do
119
119
  @chat.chat_users.size.should == 3
120
- post "/api/v1/chats/users", id: @chat.id, user_ids: @chat.active_users.first.id
120
+ post "/api/v1/chats/users", params: { id: @chat.id, user_ids: @chat.active_users.first.id }
121
121
  response.status.should == 400
122
122
  json['error'].should == "#{@chat.active_users.first.name} is already present in this chat."
123
123
  @chat.reload
@@ -125,7 +125,7 @@ describe Dummy::ChatAPI, type: :request do
125
125
  end
126
126
 
127
127
  it "should raise an error when an outsider tries to add themselves to a chat" do
128
- post "/api/v1/chats/users", id: @lurk.id, user_ids: @current_user.id
128
+ post "/api/v1/chats/users", params: { id: @lurk.id, user_ids: @current_user.id }
129
129
  response.status.should == 400
130
130
  json['error'].should == 'Only current chat participants can add users.'
131
131
  @lurk.reload
@@ -136,8 +136,8 @@ describe Dummy::ChatAPI, type: :request do
136
136
 
137
137
  context :chat do
138
138
  it "should start a new chat" do
139
- post "/api/v1/chats", user_ids:@lurker.id, message: 'a new chat'
140
- response.should be_success
139
+ post "/api/v1/chats", params: { user_ids:@lurker.id, message: 'a new chat' }
140
+ response.should be_successful
141
141
  json['creator_id'].should == @current_user.id
142
142
  Chat.last.creator.should == @current_user
143
143
  Chat.last.messages.map(&:message).first.should == 'a new chat'
@@ -145,8 +145,8 @@ describe Dummy::ChatAPI, type: :request do
145
145
  end
146
146
 
147
147
  it "should reply to a chat" do
148
- put "/api/v1/chats/#{@chat.id}", message: 'A reply.'
149
- response.should be_success
148
+ put "/api/v1/chats/#{@chat.id}", params: { message: 'A reply.' }
149
+ response.should be_successful
150
150
  ChatMessage.last.author.should == @current_user
151
151
  @sender.read_messages(Chat.last.id ).last.message.should == 'A reply.'
152
152
  @lurker.read_messages(Chat.last.id ).last.message.should == 'A reply.'
@@ -154,7 +154,7 @@ describe Dummy::ChatAPI, type: :request do
154
154
 
155
155
  it "should leave a chat" do
156
156
  delete "/api/v1/chats/#{@chat.id}"
157
- response.should be_success
157
+ response.should be_successful
158
158
  json['status'].should == true
159
159
  @chat.reload
160
160
  @chat.active_users.include?(@current_user).should == false
@@ -163,7 +163,7 @@ describe Dummy::ChatAPI, type: :request do
163
163
  it "should only allow chat participants to reply" do
164
164
  @current_user.leave_chat(@chat)
165
165
  @current_user.reload
166
- put "/api/v1/chats/#{@chat.id}", message: "I'm an interloper"
166
+ put "/api/v1/chats/#{@chat.id}", params: { message: "I'm an interloper" }
167
167
  response.status.should == 400
168
168
  json['error'].should == 'Messages: is invalid'
169
169
  @chat.messages.last.should_not == "I'm an interloper"
@@ -4,13 +4,13 @@ describe Dummy::CompanyAPI, type: :request do
4
4
  context :default_values do
5
5
  it "should respect default values" do
6
6
  get '/api/v1/companies/special/list'
7
- response.should be_success
7
+ response.should be_successful
8
8
  json.should eq({"boolean_default"=>false, "string_default"=>"foo", "integer_default"=>123})
9
9
  end
10
10
 
11
11
  it "should override default values" do
12
- get '/api/v1/companies/special/list', boolean_default: true, string_default: 'bar', integer_default: 321
13
- response.should be_success
12
+ get '/api/v1/companies/special/list', params: { boolean_default: true, string_default: 'bar', integer_default: 321 }
13
+ response.should be_successful
14
14
  json.should eq({"boolean_default"=>true, "string_default"=>"bar", "integer_default"=>321})
15
15
  end
16
16
  end
@@ -22,7 +22,7 @@ describe Dummy::CompanyAPI, type: :request do
22
22
 
23
23
  get '/api/v1/companies'
24
24
 
25
- response.should be_success
25
+ response.should be_successful
26
26
  json.length.should eq 25
27
27
  json.first['id'].should eq Company.first.id
28
28
  response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["30", "2", "25", "1", "2", "", "0"]
@@ -37,14 +37,14 @@ describe Dummy::CompanyAPI, type: :request do
37
37
 
38
38
  it "should return a list of companies" do
39
39
  get '/api/v1/companies'
40
- response.should be_success
40
+ response.should be_successful
41
41
  json.length.should > 0
42
42
  json.map{|c| c['id'].to_i}.include?(company.id).should == true
43
43
  end
44
44
 
45
45
  it "should return the specified company" do
46
46
  get "/api/v1/companies/#{company.id}"
47
- response.should be_success
47
+ response.should be_successful
48
48
  json['name'].should == company.name
49
49
  end
50
50
 
@@ -55,14 +55,14 @@ describe Dummy::CompanyAPI, type: :request do
55
55
 
56
56
 
57
57
  it "should create a company" do
58
- post "/api/v1/companies", { name: 'Test 123', short_name: 'T123' }
59
- response.should be_success
58
+ post "/api/v1/companies", params: { name: 'Test 123', short_name: 'T123' }
59
+ response.should be_successful
60
60
  json['name'].should == "Test 123"
61
61
  json['short_name'].should == "T123"
62
62
  end
63
63
 
64
64
  it "should validate a new company" do
65
- post "/api/v1/companies", { name: 'a'*257, short_name: 'a'*11 }
65
+ post "/api/v1/companies", params: { name: 'a'*257, short_name: 'a'*11 }
66
66
  response.code.should == "400"
67
67
  json['error'].should == "Name: is too long (maximum is 256 characters), Short Name: is too long (maximum is 10 characters)"
68
68
  end
@@ -70,8 +70,8 @@ describe Dummy::CompanyAPI, type: :request do
70
70
 
71
71
  it "should update the company" do
72
72
  new_name = 'New Test 1234'
73
- put "/api/v1/companies/#{company.id}", { name: new_name }
74
- response.should be_success
73
+ put "/api/v1/companies/#{company.id}", params: { name: new_name }
74
+ response.should be_successful
75
75
  company.reload
76
76
  company.name.should == new_name
77
77
  json['name'].should == new_name
@@ -79,7 +79,7 @@ describe Dummy::CompanyAPI, type: :request do
79
79
 
80
80
  it "should validate the company on update" do
81
81
  old_name = company.name
82
- put "/api/v1/companies/#{company.id}", { name: 'a'*257, short_name: 'a'*11 }
82
+ put "/api/v1/companies/#{company.id}", params: { name: 'a'*257, short_name: 'a'*11 }
83
83
  response.code.should == "400"
84
84
  company.reload
85
85
  company.name.should == old_name
@@ -87,17 +87,17 @@ describe Dummy::CompanyAPI, type: :request do
87
87
  end
88
88
 
89
89
  it "should validate json parameters" do
90
- put "/api/v1/companies/#{company.id}", { gizmos: "garbage" }
90
+ put "/api/v1/companies/#{company.id}", params: { gizmos: "garbage" }
91
91
  json["error"].should eq "gizmos must be valid JSON!"
92
92
  end
93
93
 
94
94
  it "should validate json array parameters" do
95
- put "/api/v1/companies/#{company.id}", { widgets: "[garbage[\"A\",\"B\"]" }
95
+ put "/api/v1/companies/#{company.id}", params: { widgets: "[garbage[\"A\",\"B\"]" }
96
96
  json["error"].should eq "widgets must be a valid JSON array!"
97
97
  end
98
98
 
99
99
  it "should validate json hash parameters" do
100
- put "/api/v1/companies/#{company.id}", { sprockets: "{\"foo\":\"bar\"}garbage}" }
100
+ put "/api/v1/companies/#{company.id}", params: { sprockets: "{\"foo\":\"bar\"}garbage}" }
101
101
  json["error"].should eq "sprockets must be a valid JSON hash!"
102
102
  end
103
103
 
@@ -13,7 +13,7 @@ describe Dummy::LocationAPI, type: :request do
13
13
 
14
14
  it "should return an array of camelized location entities" do
15
15
  get '/api/v1/locations'
16
- response.should be_success
16
+ response.should be_successful
17
17
  j = JSON.parse(response.body)
18
18
  j.each {|l| l.key?('childLocations').should be_truthy }
19
19
  j.each {|l| l.key?('parentLocationId').should be_truthy }
@@ -23,7 +23,7 @@ describe Dummy::LocationAPI, type: :request do
23
23
 
24
24
  it "should return a list of top level locations and their children" do
25
25
  get '/api/v1/locations'
26
- response.should be_success
26
+ response.should be_successful
27
27
  json.length.should eq 2
28
28
  json.map{|l| l['id'].to_i }.include?(location.id).should == true
29
29
 
@@ -33,15 +33,15 @@ describe Dummy::LocationAPI, type: :request do
33
33
 
34
34
 
35
35
  it "should generate basic filters on the whitelisted model attributes" do
36
- get '/api/v1/locations', { name: "TEST" }
37
- response.should be_success
36
+ get '/api/v1/locations', params: { name: "TEST" }
37
+ response.should be_successful
38
38
  json.length.should eq 1
39
39
  json.first['name'].should eq "TEST"
40
40
  end
41
41
 
42
42
  it "should parse more advanced JSON filters" do
43
- get '/api/v1/locations', filter: "{\"child_locations_locations\":{\"name\":\"Terminal A\"}}"
44
- response.should be_success
43
+ get '/api/v1/locations', params: { filter: "{\"child_locations_locations\":{\"name\":\"Terminal A\"}}" }
44
+ response.should be_successful
45
45
  json.length.should eq 1
46
46
  json.first['child_locations'].length.should eq 1
47
47
  json.first['child_locations'].first['name'].should eq "Terminal A"
@@ -49,7 +49,7 @@ describe Dummy::LocationAPI, type: :request do
49
49
 
50
50
  it "should return the specified location" do
51
51
  get "/api/v1/locations/#{location.id}"
52
- response.should be_success
52
+ response.should be_successful
53
53
  json['name'].should == location.name
54
54
  end
55
55
 
@@ -59,15 +59,15 @@ describe Dummy::LocationAPI, type: :request do
59
59
  end
60
60
 
61
61
  it "should create a location" do
62
- post "/api/v1/locations", { name: 'Test 123', kind: "terminal" }
63
- response.should be_success
62
+ post "/api/v1/locations", params: { name: 'Test 123', kind: "terminal" }
63
+ response.should be_successful
64
64
  json['name'].should == "Test 123"
65
65
  end
66
66
 
67
67
  it "should create a location with a beacon" do
68
68
  b = LocationBeacon.make(company: Company.last)
69
- post "/api/v1/locations", { name: 'Test 123', kind: "gate", beacons_attributes: [ b.attributes ] }
70
- response.should be_success
69
+ post "/api/v1/locations", params: { name: 'Test 123', kind: "gate", beacons_attributes: [ b.attributes ] }
70
+ response.should be_successful
71
71
  json['name'].should == "Test 123"
72
72
  l = Location.find(json['id'])
73
73
  created = l.beacons.first
@@ -78,8 +78,8 @@ describe Dummy::LocationAPI, type: :request do
78
78
 
79
79
  it "should create a location with gps coordinates" do
80
80
  gps = LocationGps.make
81
- post "/api/v1/locations", { name: 'Test 123', kind: "airport", gps_attributes: gps.attributes }
82
- response.should be_success
81
+ post "/api/v1/locations", params: { name: 'Test 123', kind: "airport", gps_attributes: gps.attributes }
82
+ response.should be_successful
83
83
  json['name'].should == "Test 123"
84
84
  l = Location.find(json['id'])
85
85
  created = l.gps
@@ -90,15 +90,15 @@ describe Dummy::LocationAPI, type: :request do
90
90
  end
91
91
 
92
92
  it "should validate a new location" do
93
- post "/api/v1/locations", { name: 'test' }
93
+ post "/api/v1/locations", params: { name: 'test' }
94
94
  response.code.should == "400"
95
95
  json['error'].should == "Kind: is not included in the list"
96
96
  end
97
97
 
98
98
  it "should update the location" do
99
99
  new_name = 'New Test 1234'
100
- put "/api/v1/locations/#{location.id}", { name: new_name }
101
- response.should be_success
100
+ put "/api/v1/locations/#{location.id}", params: { name: new_name }
101
+ response.should be_successful
102
102
  location.reload
103
103
  location.name.should == new_name
104
104
  json['name'].should == new_name
@@ -106,7 +106,7 @@ describe Dummy::LocationAPI, type: :request do
106
106
 
107
107
  it "should validate the location on update" do
108
108
  old_kind = location.kind
109
- put "/api/v1/locations/#{location.id}", { kind: 'bring the noise' }
109
+ put "/api/v1/locations/#{location.id}", params: { kind: 'bring the noise' }
110
110
  response.code.should == "400"
111
111
  location.reload
112
112
  location.kind.should == old_kind
@@ -116,7 +116,7 @@ describe Dummy::LocationAPI, type: :request do
116
116
  it "should destroy the location and all of its child and grandchild locations" do
117
117
  child_locations = location.child_locations.map {|l| [l.id, l.child_locations.map(&:id)] }.flatten
118
118
  delete "/api/v1/locations/#{location.id}"
119
- response.should be_success
119
+ response.should be_successful
120
120
  Location.find_by_id(location.id).should == nil
121
121
  Location.where(id: child_locations).size.should == 0
122
122
  end