测试rails xml Rest服务,我不知道错误在哪里:inheritedresources或capybara
我正在创建一个应用程序,并且使用像上面这样的继承资源控制器:
class MyResourceController < InheritedResource::Base
respond_to :xml
action :create
end
在我的黄瓜测试中,顺便说一句,我使用的是水豚,我在上面编写了一个步骤定义:
Given 'Sending a step definition' do
page.driver.post(
"/path_to_resource.xml",
<<EOF
<resource>
<attr1>value1</attr1>
<attr2>value2</attr2>
</resource>
EOF
page.status_code.should == 201
end
但是当测试运行并且我检查了测试日志时,我得到:
Started POST "/resource.xml" for 127.0.0.1 at 2011-10-26 22:03:45 -0300
Processing by MyResourceController#create as XML
AREL (0.2ms) INSERT INTO "resource" ("created_at", "updated_at", "attr1", "attr2") VALUES ('2011-10-27 01:03:45.763663', '2011-10-27 01:03:45.763663', NULL, NULL)
Completed 201 Created in 96ms (Views: 32.5ms | ActiveRecord: 0.0ms)
不幸的是,自上周以来我一直在尝试解决这个问题,但没有成功。所以我的问题是:我是否使用错误的参数调用水豚帖子或将错误的 xml 发布到控制器?
I'm creating an application and i using inheritedresource controller like the one above:
class MyResourceController < InheritedResource::Base
respond_to :xml
action :create
end
In my cucumber test, by the way, I'm using capybara, I wrote a step definition above:
Given 'Sending a step definition' do
page.driver.post(
"/path_to_resource.xml",
<<EOF
<resource>
<attr1>value1</attr1>
<attr2>value2</attr2>
</resource>
EOF
page.status_code.should == 201
end
But when the test run and I checked the test logs I got:
Started POST "/resource.xml" for 127.0.0.1 at 2011-10-26 22:03:45 -0300
Processing by MyResourceController#create as XML
AREL (0.2ms) INSERT INTO "resource" ("created_at", "updated_at", "attr1", "attr2") VALUES ('2011-10-27 01:03:45.763663', '2011-10-27 01:03:45.763663', NULL, NULL)
Completed 201 Created in 96ms (Views: 32.5ms | ActiveRecord: 0.0ms)
Unfortunally, I'm try to figure out this since last week with no success. So my question is: Am I calling capybara post with wrong parameters or posting wrong xml to controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论