Skip to content

Commit 7c54bd4

Browse files
author
=
committed
FLEX-698 let's use rotate! and raise an error if the args are wrong
1 parent b273410 commit 7c54bd4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/spark_api/models/photo.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ def rollback(version)
5959
connection.put "#{update_path}/#{self.Id}/versions/current", payload
6060
end
6161

62-
def rotate(direction)
63-
payload = { 'Photos' => [ {'Rotate' => direction }] }
62+
63+
def rotate!(direction)
64+
unless [:clockwise, :counterclockwise].include? direction.to_sym
65+
raise ArgumentError, "Photo rotate failed. '#{direction}' is not supported."
66+
end
67+
payload = { 'Photos' => [{'Rotate' => direction.to_s }] }
6468
connection.put "#{self.update_path}/#{self.Id}", payload
6569
end
6670

spec/unit/spark_api/models/photo_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484
on_put_it "should rotate a photo" do
8585
stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/rotate.json', 'success.json')
8686
subject.Id = "20110826220032167405000000"
87-
subject.rotate('clockwise')
87+
subject.rotate!('clockwise')
88+
end
89+
90+
on_put_it "should raise an exception for an invalid rotate parameter" do
91+
stub_api_put('/listings/1234/photos/20110826220032167405000000', 'listings/photos/rotate.json', 'success.json')
92+
subject.Id = "20110826220032167405000000"
93+
expect { subject.rotate!('left') }.to raise_error(ArgumentError)
8894
end
8995

9096
on_delete_it "should delete a photo" do

0 commit comments

Comments
 (0)