Guest User

Untitled

a guest
Apr 4th, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. RSpec.describe ReviewsController, type: :controller do
  4. let(:user) { create(:user) }
  5. let(:state) { State.create!(name: "Hacked") }
  6. let(:post) { Post.create(title: "State transitions", subtitle: "Can't be hacked.", content: "State transitions now they can't be hacked anymore.", author: user) }
  7.  
  8. context "a user without permission to set state" do
  9. before :each do
  10. assign_role!(user, :editor, post)
  11. sign_in user
  12. end
  13.  
  14. it "cannot transition a state by passing through state_id" do
  15. post :create, params: { review: { text: "Did I hack it??",
  16. state_id: state.id },
  17. post_id: post.id }
  18. post.reload
  19. expect(post.state).to be_nil
  20. end
  21. end
  22. end
  23.  
  24. rspec spec/controllers/reviews_controller_spec.rb -b
  25. Run options: exclude {:slow=>true}
  26. F
  27.  
  28. Failures:
  29.  
  30. 1) ReviewsController a user without permission to set state cannot transition a state by passing through state_id
  31. Failure/Error:
  32. post :create, params: { review: { text: "Did I hack it??",
  33. state_id: state.id },
  34. post_id: post.id }
  35.  
  36. ArgumentError:
  37. wrong number of arguments (given 2, expected 0)
  38. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/memoized_helpers.rb:298:in `block in let'
  39. # ./spec/controllers/reviews_controller_spec.rb:15:in `block (3 levels) in <top (required)>'
  40. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:254:in `instance_exec'
  41. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:254:in `block in run'
  42. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
  43. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
  44. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `block in run'
  45. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
  46. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
  47. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-rails-3.6.0/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
  48. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
  49. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
  50. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
  51. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
  52. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
  53. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-rails-3.6.0/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
  54. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
  55. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
  56. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
  57. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
  58. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
  59. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
  60. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `run'
  61. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
  62. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
  63. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:251:in `run'
  64. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:627:in `block in run_examples'
  65. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `map'
  66. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `run_examples'
  67. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:589:in `run'
  68. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `block in run'
  69. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `map'
  70. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `run'
  71. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
  72. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `map'
  73. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
  74. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1894:in `with_suite_hooks'
  75. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:113:in `block in run_specs'
  76. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/reporter.rb:79:in `report'
  77. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:112:in `run_specs'
  78. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:87:in `run'
  79. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
  80. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
  81. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/gems/rspec-core-3.6.0/exe/rspec:4:in `<top (required)>'
  82. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/bin/rspec:23:in `load'
  83. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/bin/rspec:23:in `<main>'
  84. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/bin/ruby_executable_hooks:15:in `eval'
  85. # /Users/romenigld/.rvm/gems/ruby-2.4.1@rails4.2.8/bin/ruby_executable_hooks:15:in `<main>'
  86.  
  87. Finished in 0.68874 seconds (files took 2.55 seconds to load)
  88. 1 example, 1 failure
  89.  
  90. Failed examples:
  91.  
  92. rspec ./spec/controllers/reviews_controller_spec.rb:14 # ReviewsController a user without permission to set state cannot transition a state by passing through state_id
  93.  
  94. post post_reviews_url, params: { review: { text: "Did I hack it??", ...
  95.  
  96. rake routes | grep review
  97. post_reviews POST /posts/:post_id/reviews(.:format) reviews#create
  98.  
  99. rspec spec/controllers/reviews_controller_spec.rb -b 1 ↵
  100. Run options: exclude {:slow=>true}
  101. F
  102.  
  103. Failures:
  104.  
  105. 1) ReviewsController a user without permission to set state cannot transition a state by passing through state_id
  106. Failure/Error:
  107. post post_reviews_url, params: { review: { text: "Did I hack it??",
  108. state_id: state.id },
  109. post_id: post.id }
  110.  
  111. ActionController::UrlGenerationError:
  112. No route matches {:action=>"create", :controller=>"reviews"} missing required keys: [:post_id]
  113.  
  114. require 'rails_helper'
  115.  
  116. RSpec.describe ReviewsController, type: :controller do
  117. let(:user) { create(:user) }
  118. let(:state) { State.create!(name: "Hacked") }
  119. let(:posting) { Post.create(title: "State transitions", subtitle: "Can't be hacked.", content: "State transitions now they can't be hacked anymore.", author: user) }
  120.  
  121. context "a user without permission to set state" do
  122. before :each do
  123. assign_role!(user, :editor, posting)
  124. sign_in user
  125. end
  126.  
  127. it "cannot transition a state by passing through state_id" do
  128. post :create, { review: { text: "Did I hack it??",
  129. state_id: state.id },
  130. post_id: posting.id }
  131. posting.reload
  132. expect(posting.state).to be_nil
  133. end
  134. end
  135. end
Add Comment
Please, Sign In to add comment