Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix up test for etag updates #32

Merged
merged 1 commit into from
Nov 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,36 @@ def check_dir_listing_content_type(content_type)
end
end

describe "PUT another JSON object" do
describe "updating that JSON object" do
before do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to group together the old_listing variables before the put request and the new ones afterwards. Also not all of those variables need to be instance variables (prefixed with @) because they're not used outside of the before block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh fuck me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@old_outer_listing_res = do_get_request("#{CONFIG[:category]}/")
@old_listing_res = do_get_request("#{CONFIG[:category]}/some-other-subdir/")
@res = do_put_request("#{CONFIG[:category]}/some-other-subdir/test-object-simple.json",
'{"new": "object"}',
{ content_type: "application/json" })
@outer_listing_res = do_get_request("#{CONFIG[:category]}/")
@listing_res = do_get_request("#{CONFIG[:category]}/some-other-subdir/")
@old_listing_res = do_get_request("#{CONFIG[:category]}/some-subdir/")
old_listing = JSON.parse @old_listing_res.body
@old_item_info = old_listing["items"]["nested-folder-object.json"]

@res = do_put_request("#{CONFIG[:category]}/some-subdir/nested-folder-object.json",
'{"foo": "bam"}',
{ content_type: "application/json" })
@item_etag = @res.headers[:etag]
@old_listing = JSON.parse @old_listing_res.body
@listing = JSON.parse @listing_res.body
@item_info = @listing["items"]["test-object-simple.json"]
@old_item_info = @old_listing["items"]["test-object-simple.json"]

@outer_listing_res = do_get_request("#{CONFIG[:category]}/")
@listing_res = do_get_request("#{CONFIG[:category]}/some-subdir/")
listing = JSON.parse @listing_res.body
@item_info = listing["items"]["nested-folder-object.json"]
end

it "works" do
# before runs for each block once, so we have to put all blocks into one
[200, 201].must_include @res.code
@item_etag.wont_be_nil
@item_etag.must_be_etag
end

it "updates the file etag in the listing" do
# updates the file etags in the folder listing
@item_info["ETag"].must_equal @item_etag.delete('"')
@item_info["ETag"].wont_equal @old_item_info["ETag"]
end

it "updates the folder etag" do
@listing_res.headers[:etag].wont_equal @old_outer_listing_res.headers[:etag]
# updates the folder etag
@listing_res.headers[:etag].wont_equal @old_listing_res.headers[:etag]
@outer_listing_res.headers[:etag].wont_equal @old_outer_listing_res.headers[:etag]
end
end
Expand Down Expand Up @@ -348,8 +348,8 @@ def check_dir_listing_content_type(content_type)
end

it "contains the correct items" do
@listing["items"].length.must_equal 6
["Capture d'écran.jpg", "my-list", "some-subdir/", "some-other-subdir/",
@listing["items"].length.must_equal 5
["Capture d'écran.jpg", "my-list", "some-subdir/",
"test-object-simple.json", "test-object-simple2.json"].each do |key|
@listing["items"].keys.must_include key
end
Expand Down Expand Up @@ -624,9 +624,8 @@ def check_dir_listing_content_type(content_type)

describe "DELETE objects" do
it "works" do
[ "test-object-simple.json", "some-other-subdir/test-object-simple.json",
"Capture d'écran.jpg", "some-subdir/nested-folder-object.json",
"my-list" ].each do |key|
[ "test-object-simple.json", "Capture d'écran.jpg",
"some-subdir/nested-folder-object.json", "my-list" ].each do |key|
res = do_delete_request("#{CONFIG[:category]}/#{key}")

res.code.must_equal 200
Expand Down