Ruby on Rails
Friday, February 10, 2017
Once I completed Michael Hartl's tutorial, I packed my homepage in a partial and called it _social_layer.html.erb
Then I inserted this partial in my new homepage and proceeded to develop my application.
Therefore, an extract of application's new homepage looks like as follows:
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="social-layer">
<%= render 'static_pages/social_layer' %>
</div>
<div role="tabpanel" class="tab-pane" id="atp-team">
<% if @atp_tournaments.any? %>
<ul>
<% @atp_tournaments.each do |tournament| %>
<li> <%= tournament.name %>: <%= tournament.category %> </li>
<% end %>
</ul>
<% end %>
</div>
...
As you can see this page is divided in sections or tabs, each one containing the respective code.
I inserted Michael Hartl's tutorial in the first tab.
There are two versions for my homepage, one dedicated to freshly registered users and one for users who have completed a certain selection.
I called these two pages _non_gamers_home.html.erb and _gamers_home.html.erb
The code above belongs to the version of the homepage dedicated to gamers (_gamers_home.html.erb)
So my home.html.erb file is made up of if/else statements and contains these two partials.
The problem is that If I run the integration test dedicated to the microposts interface (the _social_layer.html.erb partial), the test fails because all instance variables in my homepage that do not belong to the social layer partial (the first one is @atp_tournaments as you can see in the above code) result nil.
I do not understand why this test fails.
All these instance variables belong to the controller that controls the home page (static_pages_controller.rb) and should be loaded by the test.
If I change these variables with their explicit value in the above code the test passes.
-- Then I inserted this partial in my new homepage and proceeded to develop my application.
Therefore, an extract of application's new homepage looks like as follows:
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="social-layer">
<%= render 'static_pages/social_layer' %>
</div>
<div role="tabpanel" class="tab-pane" id="atp-team">
<% if @atp_tournaments.any? %>
<ul>
<% @atp_tournaments.each do |tournament| %>
<li> <%= tournament.name %>: <%= tournament.category %> </li>
<% end %>
</ul>
<% end %>
</div>
...
As you can see this page is divided in sections or tabs, each one containing the respective code.
I inserted Michael Hartl's tutorial in the first tab.
There are two versions for my homepage, one dedicated to freshly registered users and one for users who have completed a certain selection.
I called these two pages _non_gamers_home.html.erb and _gamers_home.html.erb
The code above belongs to the version of the homepage dedicated to gamers (_gamers_home.html.erb)
So my home.html.erb file is made up of if/else statements and contains these two partials.
The problem is that If I run the integration test dedicated to the microposts interface (the _social_layer.html.erb partial), the test fails because all instance variables in my homepage that do not belong to the social layer partial (the first one is @atp_tournaments as you can see in the above code) result nil.
I do not understand why this test fails.
All these instance variables belong to the controller that controls the home page (static_pages_controller.rb) and should be loaded by the test.
If I change these variables with their explicit value in the above code the test passes.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e39cdede-5bec-4eb9-81ce-8ee839d9f758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment