I have an error again that everything is working perfect in localhost but when I run "bundle exec rake test", I have an error.
Error
$ bundle exec rake test
1) Error:
UsersProfileTest#test_profile_display:
ActionView::Template::Error: undefined method `supports' for nil:NilClass
app/views/shared/_support_form.html.erb:1:in `_app_views_shared__support_form_html_erb__582342844135452036_70190475648520'
app/views/microposts/_micropost.html.erb:21:in `_app_views_microposts__micropost_html_erb___1173022564425897832_70190475500520'
app/views/users/show.html.erb:19:in `_app_views_users_show_html_erb__2940108544736749993_70190457308940'
test/integration/users_profile_test.rb:14:in `block in <class:UsersProfileTest>'
78 runs, 286 assertions, 0 failures, 1 errors, 0 skips
support_form.html.erb
<% if support = current_user.supports.find_by_micropost_id(micropost.id) %>
<% micropost.supports.each do |support| %>
<% if current_user?(support.user) %>
<button class="btn" type="submit">
<%= link_to "Not Support", [support.micropost, support], method: :delete %>
</button>
<% end %>
<% end %>
<% else %>
<%= form_for ([micropost, @support]) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.hidden_field :micropost_id %>
<%= f.hidden_field :user_id %>
<button class="btn" type="submit">
Support
</button>
<% end %>
<% end %>
supports_controller.rb
def create
@support = Support.new(micropost_id: params[:micropost_id], user: current_user)
if @support.save
redirect_to request.referrer || root_url
else
redirect_to request.referrer || root_url
end
end
def destroy
@support.destroy
redirect_to request.referrer || root_url
end
supports_controller_test.rb
require 'test_helper'
class SupportsControllerTest < ActionController::TestCase
def setup
@user = users(:michael)
@micropost = microposts(:orange)
@support = @user.supports.build(micropost_id:@micropost.id)
end
end
Aucun commentaire:
Enregistrer un commentaire