Skip to content

Commit 7daf21d

Browse files
committed
fixes all specs bar one
1 parent f34ff1b commit 7daf21d

20 files changed

Lines changed: 40 additions & 40 deletions

spec/controllers/metadata_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module PlaceOS::Api
7979
headers: Spec::Authentication.headers,
8080
)
8181

82-
result.status_code.should eq 201
82+
result.success?.should be_true
8383

8484
new_metadata = Model::Metadata::Interface.from_json(result.body)
8585
found = Model::Metadata.for(parent.id.as(String), meta.name).first
@@ -105,7 +105,7 @@ module PlaceOS::Api
105105
headers: Spec::Authentication.headers,
106106
)
107107

108-
result.status_code.should eq 201
108+
result.success?.should be_true
109109

110110
new_metadata = Model::Metadata::Interface.from_json(result.body)
111111
found = Model::Metadata.for(parent_id, meta.name).first
@@ -125,7 +125,7 @@ module PlaceOS::Api
125125
headers: Spec::Authentication.headers,
126126
)
127127

128-
result.status_code.should eq 200
128+
result.success?.should be_true
129129

130130
update_response_meta = Model::Metadata::Interface.from_json(result.body)
131131
update_response_meta.details.as_h["bye"]?.should be_nil

spec/controllers/modules_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ module PlaceOS::Api
265265
)
266266

267267
result.success?.should be_false
268-
result.status_code.should eq 406
268+
result.status_code.should eq 422
269269
end
270270

271271
it "pings a module" do

spec/controllers/system-triggers_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module PlaceOS::Api
120120
path = SystemTriggers.base_route.gsub(/:sys_id/, sys.id) + id
121121

122122
result = client.delete(path: path, headers: Spec::Authentication.headers)
123-
result.status_code.should eq 200
123+
result.success?.should be_true
124124

125125
Model::TriggerInstance.find(id.as(String)).should be_nil
126126
end

spec/controllers/systems_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module PlaceOS::Api
2828
headers: headers,
2929
)
3030

31-
result.status_code.should eq 200
31+
result.success?.should be_true
3232
system = Model::ControlSystem.from_trusted_json(result.body)
3333
system.modules.should_not contain mod_id
3434
system

src/placeos-rest-api/controllers/api_keys.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module PlaceOS::Api
88
###############################################################################################
99

1010
before_action :can_read, only: [:index, :show]
11-
before_action :can_write, only: [:create, :update, :destroy, :update_alt]
11+
before_action :can_write, only: [:create, :update, :destroy]
1212

1313
before_action :check_admin, except: :inspect_key
1414

src/placeos-rest-api/controllers/application.cr

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ module PlaceOS::Api
1313

1414
# Customise the request body parser
1515
add_parser("application/json") do |klass, body_io|
16-
if klass.is_a? ActiveModel::Model
17-
object = klass.new
16+
json = body_io.gets_to_end
17+
object = klass.from_json(json)
18+
19+
# TODO:: try to improve this double parsing
20+
if object.is_a?(::PlaceOS::Model::ModelBase)
21+
object = object.class.new
1822
# we clear the changes information so we can track what was assigned from the JSON
1923
object.clear_changes_information
20-
object.assign_attributes_from_json(body_io)
21-
object
22-
else
23-
klass.from_json(body_io)
24+
object.assign_attributes_from_json(json)
2425
end
26+
27+
object
2528
end
2629

2730
# Helpers for controller responses
@@ -146,7 +149,7 @@ module PlaceOS::Api
146149

147150
# CONFLICT if there is a version clash
148151
@[AC::Route::Exception(Error::Conflict, status_code: HTTP::Status::CONFLICT)]
149-
def resource_requires_authentication(error) : CommonError
152+
def resource_conflict(error) : CommonError
150153
Log.debug { error.message }
151154
CommonError.new(error, false)
152155
end

src/placeos-rest-api/controllers/authentications.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module PlaceOS::Api
1010
###############################################################################################
1111

1212
before_action :can_read, only: [:index, :show]
13-
before_action :can_write, only: [:create, :update, :destroy, :remove, :update_alt]
13+
before_action :can_write, only: [:create, :update, :destroy, :remove]
1414

1515
before_action :check_admin
1616

src/placeos-rest-api/controllers/brokers.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module PlaceOS::Api
1010
###############################################################################################
1111

1212
before_action :can_read, only: [:collection, :show]
13-
before_action :can_write, only: [:create, :update, :destroy, :remove, :update_alt]
13+
before_action :can_write, only: [:create, :update, :destroy, :remove]
1414

1515
before_action :check_admin, except: [:collection, :show]
1616
before_action :check_support, only: [:collection, :show]

src/placeos-rest-api/controllers/domains.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module PlaceOS::Api
88
###############################################################################################
99

1010
before_action :can_read, only: [:index, :show]
11-
before_action :can_write, only: [:create, :update, :destroy, :remove, :update_alt]
11+
before_action :can_write, only: [:create, :update, :destroy, :remove]
1212

1313
before_action :check_admin, except: [:index, :show]
1414
before_action :check_support, only: [:index, :show]

src/placeos-rest-api/controllers/drivers.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module PlaceOS::Api
88
###############################################################################################
99

1010
before_action :can_read, only: [:index, :show]
11-
before_action :can_write, only: [:create, :update, :destroy, :remove, :update_alt]
11+
before_action :can_write, only: [:create, :update, :destroy, :remove]
1212

1313
before_action :check_admin, except: [:index, :show]
1414
before_action :check_support, only: [:index, :show]

0 commit comments

Comments
 (0)