* Upwork Ruby on Rails Test Answer N0 1.
Question:
Unit tests are used to test which of the following components of Ruby on Rails?
Answers:
Models
* Upwork Ruby on Rails Test Answer N0 2.
Question:
Which of the following commands will test a particular test case, given that the tests are contained in the file test/unit/demo_test.rb, and the particular test case is test_one?
Answers:
$ ruby -Itest test/unit/demo_test.rb -n test_one
* Upwork Ruby on Rails Test Answer N0 3.
Question:
Rails automatically requires certain files in an application. Which of the following files are automatically included without an explicit 'require' being necessary?
Answers:
All files in models, views, controllers, and any init.rb in plugins.
* Upwork Ruby on Rails Test Answer N0 4.
Question:
Select all incorrect statements regarding the Ruby Version Manager (RVM):
Answers:
RVM provides a revision control tool to maintain current and historical versions of files such as source code, web pages, and documentation.
* Upwork Ruby on Rails Test Answer N0 5.
Question:
Answers:
nil, 0, and any positive integer
* Upwork Ruby on Rails Test Answer N0 6.
Question:
What is the behavior of class variables with subclasses?
Answers:
Class variables are shared between between all classes in the hierarchy.
* Upwork Ruby on Rails Test Answer N0 7.
Question:
In a has_many association, what is the difference between build and new? // user.rb has_many :posts // post.rb belongs_to :user
Answers:
'build' sets the foreign key and adds it to the collection.
* Upwork Ruby on Rails Test Answer N0 8.
Question:
If a method #decoupage(n) is described as O(n^2), what does that mean?
Answers:
The worst case run time is proportional to the size of the square of the method's input.
* Upwork Ruby on Rails Test Answer N0 9.
Question:
Which of the following controller actions (by default) are best suited to handle the GET HTTP request?
Answers:
index
* Upwork Ruby on Rails Test Answer N0 10.
Question:
In a Rails application, a Gemfile needs to be modified to make use of sqlite3-ruby gems. Which of the following options will use these gems, as per the new Gemfile?
Answers:
bundle install
* Upwork Ruby on Rails Test Answer N0 11.
Question:
What component of Rails are tested with unit tests?
Answers:
Models
* Upwork Ruby on Rails Test Answer N0 12.
Question:
How can a partial called "cart" be rendered from a controller called "ProductsController", assuming the partial is in a directory called "shared"?
Answers:
render :partial => 'shared/cart'
* Upwork Ruby on Rails Test Answer N0 13.
Question:
Which of the following options is used to create a form HTML in the erb files?
Answers:
form_for
* Upwork Ruby on Rails Test Answer N0 14.
Question:
Given below are two statements regarding the Ruby programming language: Statement X: "redo" restarts an iteration of the most internal loop, without checking loop condition. Statement Y: "retry" restarts the invocation of an iterator call. Also, arguments to the iterator are re-evaluated. Which of the following options is correct?
Answers:
Both statements are correct.
* Upwork Ruby on Rails Test Answer N0 15.
Question:
Which of the following options, when passed as arguments, skips a particular validation?
Answers:
:validate => false
* Upwork Ruby on Rails Test Answer N0 16.
Question:
Which of the following is not a built-in Rails caching strategy used to reduce database calls?
Answers:
Query Caching
* Upwork Ruby on Rails Test Answer N0 17.
Question:
How can a value be stored so that it's shared across an entire request (i.e. make it accessible in controllers, views and models)?
Answers:
Create a Singleton and store it in a class variable
* Upwork Ruby on Rails Test Answer N0 18.
Question:
Which is the best way to add a page-specific JavaScript code in a Rails 3 app? <%= f.radio_button :rating, 'positive', :onclick => "$('some_div').show();" %>
Answers:
<% content_for :head do %> <script type="text/javascript"> <%= render :partial => "my_view_javascript" </script> <% end %> Then in layout file <head> ... <%= yield :head %> </head>
* Upwork Ruby on Rails Test Answer N0 19.
Question:
Which part of the MVC stack does ERB or HAML typically participate in?
Answers:
View
* Upwork Ruby on Rails Test Answer N0 20.
Question:
Which of the following choices will write routes for the API versioning scenario described below? /api/users returns a 301 to /api/v2/users /api/v1/users returns a 200 of users index at version 1 /api/v3/users returns a 301 to /api/v2/users /api/asdf/users returns a 301 to /api/v2/users
Answers:
• namespace :api do namespace :v1 do resources :users end namespace :v2 do resources :users end match 'v:api/*path', :to => redirect("/api/v2/%{path}") match '*path', :to => redirect("/api/v2/%{path}") end • namespace :api do resources :users end namespace :v2 do resources :users end match 'v:api/*path', :to => redirect("/api/v1/%{path}") match '*path', :to => redirect("/api/v1/%{path}") end • namespace :api do scope :module => :v3, ¤t_api_routes namespace :v3, ¤t_api_routes namespace :v2, ¤t_api_routes namespace :v1, ¤t_api_routes match ":api/*path", :to => redirect("/api/v3/%{path}") end • None of these
* Upwork Ruby on Rails Test Answer N0 21.
Question:
Which of the following replaced the Prototype JavaScript library in Ruby on Rails as the default JavaScript library?
Answers:
jQuery
* Upwork Ruby on Rails Test Answer N0 22.
Question:
What is the difference between _url and _path while being used in routes?
Answers:
_url is absolute while _path is relative.
* Upwork Ruby on Rails Test Answer N0 23.
Question:
Answers:
a href='Angel'>/users/1</a
* Upwork Ruby on Rails Test Answer N0 24.
Question:
Users who are new to MVC design often ask how to query data from Views. Is this possible? And if so, is this a good idea?
Answers:
It is possible, but it is a bad idea because Views should only be responsible for displaying objects passed to them
* Upwork Ruby on Rails Test Answer N0 25.
Question:
When using full-page caching, what happens when an incoming request matches a page in the cache?
Answers:
The web-server serves the file directly from disk, bypassing Rails
* Upwork Ruby on Rails Test Answer N0 26.
Question:
What is the best way to get the current request URL in Rails?
Answers:
request.url
* Upwork Ruby on Rails Test Answer N0 27.
Question:
Which of the following commands will clear out sample users from the development database?
Answers:
rake db:reset
* Upwork Ruby on Rails Test Answer N0 28.
Question:
Which of the following options will disable the rendering of the view associated with a controller action?
Answers:
render :layout=>false
* Upwork Ruby on Rails Test Answer N0 29.
Question:
What is the Singleton design pattern?
Answers:
A class for which there is only ever one instance.
* Upwork Ruby on Rails Test Answer N0 30.
Question:
Which of the following code samples will get the index of |page| inside of a loop?
Answers:
<% @images.each_with_index do |page, index| %> <% end %>
* Upwork Ruby on Rails Test Answer N0 31.
Question:
Which of the following is not true about log levels in Ruby on Rails?
Answers:
The available log levels are: :debug, :info, :warn, :error, and :fatal, corresponding to the log level numbers from 1 up to 5 respectively.
* Upwork Ruby on Rails Test Answer N0 32.
Question:
Which of the following validations in Rails checks for null fields?
Answers:
validates_presence_of
* Upwork Ruby on Rails Test Answer N0 33.
Question:
In order to enable locking on a table, which of the following columns is added?
Answers:
lock_version column
* Upwork Ruby on Rails Test Answer N0 34.
Question:
Answers:
1) false 2) true 3) NoMethodError: undefined method `empty?' for nil:NilClass 4) true 5) NoMethodError: undefined method `any?' for "":String 6) false
* Upwork Ruby on Rails Test Answer N0 35.
Question:
Which of the following will return a User object when used with a model which deals with a table named User?
Answers:
User.find
* Upwork Ruby on Rails Test Answer N0 36.
Question:
Which of the following is the correct way to know the Rails root directory path?
Answers:
Rails.root
* Upwork Ruby on Rails Test Answer N0 37.
Question:
For the String class, what's the difference between "#slice" and "#slice!"?
Answers:
"#slice" returns a new object, "#slice!" destructively updates — mutates — the object's value.
* Upwork Ruby on Rails Test Answer N0 38.
Question:
Which of the following is the correct way to rollback a migration?
Answers:
rake db:rollback STEP=N (N is the migration number to be rollbacked)
* Upwork Ruby on Rails Test Answer N0 39.
Question:
What is the output of the following code? "test"*5
Answers:
testtesttesttesttest
* Upwork Ruby on Rails Test Answer N0 40.
Question:
If a controller is named "Users", what would its helpers module be called?
Answers:
UsersHelper
* Upwork Ruby on Rails Test Answer N0 41.
Question:
Which of the following is the correct syntax for an input field of radio buttons in form_for?
Answers:
<%= f.radio_button :contactmethod, 'sms' %>
* Upwork Ruby on Rails Test Answer N0 42.
Question:
Answers:
A
* Upwork Ruby on Rails Test Answer N0 43.
Question:
In the case of Rails application performance optimization, select all valid ways to do assets compilation:
Answers:
Running the rake task with the assets:precompile parameter when CSS and JavaScript files are updated.
* Upwork Ruby on Rails Test Answer N0 44.
Question:
Which of the following actions is fired by default when a new controller is created?
Answers:
Index
* Upwork Ruby on Rails Test Answer N0 45.
Question:
What does REST stand for?
Answers:
REpresentational State Transfer
* Upwork Ruby on Rails Test Answer N0 46.
Question:
What is green-threading?
Answers:
When threads are emulated by a virtual machine or interpreter.
* Upwork Ruby on Rails Test Answer N0 47.
Question:
What is the convention for methods which end with a question mark? e.g. #all?, #kind_of?, directory?
Answers:
They should always return a boolean value.
* Upwork Ruby on Rails Test Answer N0 48.
Question:
What is the output of the following code? $val = 20 print "Sample Text\n" if $val
Answers:
Sample Text
* Upwork Ruby on Rails Test Answer N0 49.
Question:
Choose the best way to implement sessions in Rails 3: A) Using CookieStore B) By creating a session table and setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store C) By setting config/initializers/session_store.rb with Rails.application.config.session_store :active_record_store only
Answers:
B
* Upwork Ruby on Rails Test Answer N0 50.
Question:
Which of the following is the default way that Rails seeds data for tests?
Answers:
Fixtures
* Upwork Ruby on Rails Test Answer N0 51.
Question:
When a new controller named "admin2" is created, the JS and the CSS files are created in:
Answers:
assets
* Upwork Ruby on Rails Test Answer N0 52.
Question:
If a float is added to an integer, what is the class of the resulting number? i.e. 1.0 + 2
Answers:
FLOAT
* Upwork Ruby on Rails Test Answer N0 53.
Question:
Which of the following methods is used to check whether an object is valid or invalid?
Answers:
.valid? and .invalid?
* Upwork Ruby on Rails Test Answer N0 54.
Question:
Which of the following serves as a structural skeleton for all HTML pages created?
Answers:
application.html.erb
* Upwork Ruby on Rails Test Answer N0 55.
Question:
Suppose a model is created as follows: rails generate model Sales rake db:migrate What would be the best way to completely undo these changes, assuming nothing else has changed in the meantime?
Answers:
rake db:rollback; rails destroy model Sales
* Upwork Ruby on Rails Test Answer N0 56.
Question:
Which of the following is the correct way to skip ActiveRecords in Rails 3?
Answers:
Which of the following is the correct way to skip ActiveRecords in Rails 3?
* Upwork Ruby on Rails Test Answer N0 57.
Question:
Which of the following assertions are used in testing views?
Answers:
assert_select_encoded
* Upwork Ruby on Rails Test Answer N0 58.
Question:
Given the following code, where is the "party!" method available? module PartyAnimal def self.party! puts "Hard! Better! Faster! Stronger!" end end class Person include PartyAnimal end
Answers:
PartyAnimal.party!
* Upwork Ruby on Rails Test Answer N0 59.
Question:
What does the 4xx series of HTTP errors represent?
Answers:
They are intended for cases in which the server seems to have encountered an error.
* Upwork Ruby on Rails Test Answer N0 60.
Question:
What exception cannot be handled with the rescue_from method in the application controller? e.g class ApplicationControllers < ActionController::Base rescue_from Exception, with: error_handler .......... end
Answers:
Server errors
* Upwork Ruby on Rails Test Answer N0 61.
Question:
Which of the following will disable browser page caching in Rails?
Answers:
expire_page(:controller => 'products', :action => 'index')
* Upwork Ruby on Rails Test Answer N0 62.
Question:
Answers:
The HTML page will render with the title: Ruby on Rails sample application |.
* Upwork Ruby on Rails Test Answer N0 63.
Question:
In a Rails application, the developmental and production configuration are stored in the:
Answers:
config/environment folder
* Upwork Ruby on Rails Test Answer N0 64.
Question:
Which of the following is true about writing tests for a Ruby on Rails application?
Answers:
• Rails semi-automates the process of writing tests. It starts by producing skeleton test code in the background while models and controllers are being written. • Running tests in Rails ensures that the code adheres to the desired functionality even after major code refactoring. • Rails tests can simulate browser requests, and thus test the application's response without having to test it through a browser. • All of these.
* Upwork Ruby on Rails Test Answer N0 65.
Question:
With the two models Hive and Bee; when creating a belongs_to association from the Bee model to Hive, what is the foreign key generated on Bee?
Answers:
hive_id
* Upwork Ruby on Rails Test Answer N0 66.
Question:
What is the recommended Rails way to iterate over records for display in a view?
Answers:
Implicitly loop over a set of records, and send the partial being rendered a :collection.
* Upwork Ruby on Rails Test Answer N0 67.
Question:
What is difference between "has_one" and "belong_to"?
Answers:
"belong_to" should be used in a model whose table have foreign keys while "has_one" is used with an associated table.
* Upwork Ruby on Rails Test Answer N0 68.
Question:
where we use attr_accessor and attr_accessible in rails ?
Answers:
model
* Upwork Ruby on Rails Test Answer N0 69.
Question:
What is the output of the following code? puts "aeiou".sub(/[aeiou]/, '*')
Answers:
*eiou
* Upwork Ruby on Rails Test Answer N0 70.
Question:
What declaration would you use to set the layout for a controller?
Answers:
layout 'new_layout'
* Upwork Ruby on Rails Test Answer N0 71.
Question:
Which of the following statements is incorrect?
Answers:
Rails does not support ODBC connectivity.
* Upwork Ruby on Rails Test Answer N0 72.
Question:
What is the output of the following Ruby code? puts "The multiplication output of 10,10,2 is #{10*10*2}"
Answers:
The multiplication output of 10,10,2 is 200.
* Upwork Ruby on Rails Test Answer N0 73.
Question:
What is best way to create primary key as a string field instead of integer in rails.
Answers:
when creating a new table don't add primary key using this create_table users, :id => false do |t| t.string :id, :null => false ...... end execute("ALTER TABLE users ADD PRIMARY KEY (id)") if not using id as primary key then in users model add the following line class User < ActiveRecord::Base self.primary_key = "column_name" .... end
* Upwork Ruby on Rails Test Answer N0 74.
Question:
There is a table named Product in a Rails application. The program is required to fetch any 5 rows where the productid is 2. Which of the following is the correct option to perform this action?
Answers:
Product.find(:productid=>2), :limit=>5
* Upwork Ruby on Rails Test Answer N0 75.
Question:
Which of the following commands adds the data model info to the model file?
Answers:
generate model
* Upwork Ruby on Rails Test Answer N0 76.
Question:
Which gem is used to install a debugger in Rails 3?
Answers:
gem "ruby-debug19"
* Upwork Ruby on Rails Test Answer N0 77.
Question:
Is an AJAX call synchronous or asynchronous?
Answers:
Either; it is configurable
* Upwork Ruby on Rails Test Answer N0 78.
Question:
If a model called BlogComment is defined, what would its DB table be called?
Answers:
blog_comments
* Upwork Ruby on Rails Test Answer N0 79.
Question:
Which of the following items are stored in the models subdirectory?
Answers:
database classes
* Upwork Ruby on Rails Test Answer N0 80.
Question:
What is the output of the following code in Ruby? x= "A" + "B" puts x y= "C" << "D" puts y
Answers:
AB CD
* Upwork Ruby on Rails Test Answer N0 81.
Question:
In a Rails Migration, which of the following will make a column unique, and then have it indexed?
Answers:
add_index :table_name, :column_name, :unique => true
* Upwork Ruby on Rails Test Answer N0 82.
Question:
How can a partial called "cart" be rendered from a controller called "ProductsController", assuming the partial is in a directory called "shared"?
Answers:
render :partial => 'shared/cart'
* Upwork Ruby on Rails Test Answer N0 83.
Question:
What is the difference between :dependent => :destroy and :dependent => :delete_all in Rails?
Answers:
In :destroy, associated objects are destroyed alongside the object by calling their :destroy method, while in :delete_all, they are destroyed immediately, without calling their :destroy method.
* Upwork Ruby on Rails Test Answer N0 84.
Question:
Using ERB for views, what filename should be given to a partial called 'login'?
Answers:
_login.html.e
* Upwork Ruby on Rails Test Answer N0 85.
Question:
Which of the following HTML template languages are supported by Ruby?
Answers:
Embedded Ruby