到目前为止我还没有找到任何方法。
https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.Client.options
Run Code Online (Sandbox Code Playgroud)
显示选项允许 request.body 通过 get 请求,但找不到任何方式通过 post 请求传递。任何想法,我一直在寻找几个小时。
这里发生了什么:
我希望"取消预订"按钮在点击后有一个超时.首次点击它会更改为显示"确认取消"按钮.几秒钟后,它返回"取消预订".
我的控制台给了我:
TypeError: $timeout is not a function
Run Code Online (Sandbox Code Playgroud)
我正在使用AngularJS $ timeout:
控制器:
'use strict';
module.controller('ReservationItemCtrl', ['$scope', '$stateParams', '$RPC',
function($scope, $stateParams, $RPC, $timeout) {
......other stuff.......
......other stuff.......
$scope.toggleCancelReservation = function(reservation) {
reservation.clickedcancel = true;
$timeout(function(){reservation.clickedcancel = false}, 4000);
};
}
]);
Run Code Online (Sandbox Code Playgroud)
模板:
<button ng-show="!reservation.value.deleted && !deleted.value"
class="btn btn-danger"
ng-show="canCancel(reservation)" ng-if="!reservation.clickedcancel" ng-click="toggleCancelReservation(reservation)">
Cancel With Refund
</button>
<button type="button" class="btn btn-danger" ng-if="reservation.clickedcancel == true" ng-click="deleteReservation();" style="margin-top: -4px;">
Confirm Cancellation
</button>
Run Code Online (Sandbox Code Playgroud)
我准确地在第一次点击时切换按钮然后再次点击它会正确取消/删除预订,但如果我在第一次点击后没有做任何事情,那么超时永远不会将其返回到原始按钮.在我的控制台中,$timeout is not a function由于某种原因我看到了吗?我把它包含在我的控制器中.我错过了什么吗?
我的提案控制器有以下操作:
def show
@proposal = Proposal.find(params[:id])
authorize @proposal
end
Run Code Online (Sandbox Code Playgroud)
我有以下政策:
class ProposalPolicy
attr_reader :current_user, :proposal
Run Code Online (Sandbox Code Playgroud)
如何重定向到特定页面.如果在尝试转到显示页面时拒绝权限,请说索引提案或根页?
当我在没有正确权限的情况下导航到它时,我只会得到一个带有以下内容的rails错误页面:
not allowed to show? this<proposal OBJ ispsum lorem>
Run Code Online (Sandbox Code Playgroud)
我只是希望他们有一个简单的通知并重定向到另一个页面.什么是最好的方法呢?我在show视图中猜测某种if语句但到目前为止还没有任何工作.
def initialize(current_user, proposal)
@current_user = current_user
@proposal = proposal
end
def show?
@proposal.published? or @proposal.proposer == @current_user
end
end
Run Code Online (Sandbox Code Playgroud) model-view-controller authorization ruby-on-rails ruby-on-rails-4 pundit
我正在为我们的应用程序编写一些测试,但不确定我在这里测试的内容是否正确。这是我的测试。
def test_ReservationExtensionFalseWrongResource(self):
'does not create a reservation that is an extension if different resource'
try:
reservation1 = Reservation.objects.create(user=self.regularUser1, resource=self.resource1, modality=self.modality, timeFrom=datetime(2015, 6, 11, 20, tzinfo=pytz.utc), timeTo=datetime(2015, 6, 11, 21, tzinfo=pytz.utc), count=1, notes=None, extendedReservation=None)
reservation = create_reservation(self.regularUser2, self.regularUser2, None, self.resource2, self.modality, datetime(2015, 6, 11, 20, tzinfo=pytz.utc), datetime(2015, 6, 11, 21, tzinfo=pytz.utc), 1, reservation1.uuid)
self.assertTrue(False, "Should not create reservation")
except Exception, e:
self.assertTrue(True, "Not authorized")
Run Code Online (Sandbox Code Playgroud)
我想确保如果保留扩展属于不同的资源,则无法创建保留扩展,因此该行应该在 try 块中失败:
reservation = create_reservation(self.regularUser2, self.regularUser2, None, self.resource2, self.modality, datetime(2015, 6, 11, 20, tzinfo=pytz.utc), datetime(2015, …Run Code Online (Sandbox Code Playgroud) django ×2
python ×2
unit-testing ×2
angularjs ×1
javascript ×1
pundit ×1
settimeout ×1
timeout ×1