I have a app with this kind of setup:
User (id)
Room (id, private (boolean)
RoomMember(user_id, room_id, banned (boolean)
These are the use cases I want to write tests for:
- If the room is not private the user can join and is redirect to the right url
- If the room is private, the user is redirect to the Enter Password Page
- If the user has been banned, they are redirect to '/'
What's开发者_如何学Python the right rails rspec way to test these user stories?
Thanks
The following should be possible (with your modification):
describe "User Permissions" do
  it "should allow users to join public rooms" do
    user = User.new
    room = Room.new( private: false )
    get "[your_action]"
    response.should render_template( "path/to/room/show/template" )
  end
  it "should honor privacy" do
    user = User.new
    room = Room.new( private: true )
    get "[your_action]"
    response.should redirect_to( action: '[enter_password_action]' )
  end
  it "shouldn't allow banned users to enter rooms" do
    user = User.new( banned: true )
    room = Room.new
    get "[your_action]"
    response.should redirect_to( "/" )
  end
end
More on writing Rspec Rails Controller tests can be found here.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论