test/functional/test_back.rb in spontaneous-0.2.0.beta5 vs test/functional/test_back.rb in spontaneous-0.2.0.beta6
- old
+ new
@@ -894,11 +894,11 @@
}
end
it "adds an alias to a box" do
home.featured_jobs.contents.length.must_equal 0
- auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_id' => Job.first.id, "position" => 0
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => Job.first.id, "position" => 0
assert last_response.ok?, "Recieved #{last_response.status} not 200"
last_response.content_type.must_equal "application/json;charset=utf-8"
home.reload
home.featured_jobs.contents.length.must_equal 1
a = home.featured_jobs.first
@@ -906,20 +906,38 @@
a.target.must_equal Job.first
required_response = {
:position => 0,
:entry => home.featured_jobs.contents.first.export(user)
}
- Spot::JSON.parse(last_response.body).must_equal required_response
+ Spot::JSON.parse(last_response.body).first.must_equal required_response
end
+ it "allows for adding multiple aliases to a box" do
+ home.featured_jobs.contents.length.must_equal 0
+ jobs = Job.all[0..1]
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => jobs.map(&:id), "position" => 0
+ assert last_response.ok?, "Recieved #{last_response.status} not 200"
+ home.reload
+ home.featured_jobs.contents.length.must_equal 2
+ home.featured_jobs.each_with_index do |a, i|
+ assert a.alias?
+ a.target.must_equal jobs[i]
+ end
+ response = Spot::JSON.parse(last_response.body)
+ response[0][:position].must_equal 0
+ response[1][:position].must_equal 1
+ response[0][:entry].must_equal home.featured_jobs[0].export(user)
+ response[1][:entry].must_equal home.featured_jobs[1].export(user)
+ end
+
it "adds an alias to a box at any position" do
home.featured_jobs << Job.new
home.featured_jobs << Job.new
home.featured_jobs << Job.new
home.save.reload
home.featured_jobs.contents.length.must_equal 3
- auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_id' => Job.first.id, "position" => 2
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => Job.first.id, "position" => 2
assert last_response.ok?, "Recieved #{last_response.status} not 200"
last_response.content_type.must_equal "application/json;charset=utf-8"
home.reload
home.featured_jobs.contents.length.must_equal 4
a = home.featured_jobs[2]
@@ -927,11 +945,11 @@
a.target.must_equal Job.first
required_response = {
:position => 2,
:entry => home.featured_jobs[2].export(user)
}
- Spot::JSON.parse(last_response.body).must_equal required_response
+ Spot::JSON.parse(last_response.body).first.must_equal required_response
end
it "interfaces with lists of non-content targets" do
begin
@@ -949,10 +967,10 @@
nil
}
end
box = home.boxes[:featured_jobs]
box._prototype.allow LinkedSomething
- auth_post "/@spontaneous/alias/#{home.id}/#{box.schema_id.to_s}", 'alias_id' => LinkedSomething.schema_id.to_s, 'target_id' => @target_id, "position" => 0
+ auth_post "/@spontaneous/alias/#{home.id}/#{box.schema_id.to_s}", 'alias_id' => LinkedSomething.schema_id.to_s, 'target_ids' => @target_id, "position" => 0
assert last_response.status == 200, "Expected a 200 but got #{last_response.status}"
home.reload
a = home.featured_jobs[0]
assert a.alias?
a.target.must_equal @target