Notes posted by taimoorchangaiz
RSS feedAnothery way
This Worked For Me
require File.expand_path('../app/models/extenstions/active_record_ext', File.dirname(__FILE__))
I did this in application.rb
isolate_namespace description with example
Normally when you create controllers, helpers and models inside an engine, they are treated as if they were created inside the application itself. This means that all helpers and named routes from the application will be available to your engine’s controllers as well.
However, sometimes you want to isolate your engine from the application, especially if your engine has its own router. To do that, you simply need to call isolate_namespace. This method requires you to pass a module where all your controllers, helpers and models should be nested to:
module MyEngine class Engine < Rails::Engine isolate_namespace MyEngine end
end
With such an engine, everything that is inside the MyEngine module will be isolated from the application.
Detail reference: http://edgeapi.rubyonrails.org/classes/Rails/Engine.html
Html inside Lable tag
I need this
<label> Show <select size="1" name="dyntable_length" aria-controls="dyntable"> <option value="10" selected="selected">10</option> <option value="25">25</option> <option value="50">50</option> <option value="100">100</option> </select> entries </label>
I made a helper method:
def entries_lablel() label_tag '' do concat 'Show ' concat content_tag(:select, options_for_select([10, 25, 50, 100]), {name: 'dyntable_length', size: 1} ) concat ' entries' end end
and In my html.erb file I called it
<%= entries_lablel %>
You can pass paramateres to make it more generic also You can add multiple select elements or any other element using the same
as_null_object working
It only listen for the messages we tell it to expect and ignore any other messages.
For example:
spec/codebreaker/game_spec.rb
module Codebreaker describe Game do describe "#start" do before(:each) do @output = double('output').as_null_object @game = Game.new(@output) end it "sends a welcome message" do @output.should_receive(:puts).with('Welcome to Codebreaker!') @game.start end it "prompts for the first guess" do @output.should_receive(:puts).with('Enter Guess:') @game.start end end end end
In first example we are expecting ‘Welcone to Codebreaker!’ while in second example we expect ‘Enter Guess:’
and in before(:each) first line we are using as_null_object which allowing us to only check if expected string exists in game.start method then it will pass.
lib/codebreaker/game.rb
module Codebreaker class Game def initialize(output) @output = output end def start @output.puts 'Welcome to Codebreaker!' @output.puts 'Enter Guess:' end end end
Help Link :)
www.relishapp.com/rspec/rspec-mocks/docs/message-expectations/receive-counts!