October 2007
3 posts
RSpec Views: Looking for tags with certain onclick...
Thanks to agile on #dallas.rb for helping me get to this. A great resource for all things tag and attribute related in regards to rails http://api.rubyonrails.com/classes/HTML/Selector.html
describe "/questions/show that logged in user is not monitoring" do
it_should_behave_like "/questions/show"
it "should have a link to start monitoring" do
response.should...
RSpec Logged In Helper
This is what I’m using to help out with actions and views that require a logged in user
spec_helper.rb
module LoggedInHelper
def mock_globals
@current_user = mock_model(User, :id => 1)
end
end
describe "Logged In Action", :shared => true do
include LoggedInHelper
before(:each) do
mock_globals
controller.stub!(:current_user).and_return(@current_user)
...
Using flash for javascript messages
Using flash[:notice] doesn’t work so well with AJAX calls. Adding a “js_notice” key to flash has helped me in several places.
respond_to do |format|
if @question_monitor.save
format.js {
flash[:js_notice] = "You will now be alerted to any new activity on this question."
}
else
format.js {
flash[:js_notice] =...