Upwork Test Answers: Get all the correct answers of most recent and possible Upwork Tests A to Z (Updated on Jan, 2016)
Cover Letter Templates: These cover letter samples are not only for Upwork job, but also you will have some idea about your real life job
Freelance Profile Overviews: Different Profile samples and overviews of experts, advanced and intermediate level freelancers
For Newbie of Upwork: Upwork Help - How to apply for a job in Upwork with 10 most important articles about Upwork

A to Z View - All Upwork Test Answers

Ruby on Rails Test Answers

Here you will find Upwork Ruby on Rails Test Answers of Web Development Category with 82 updated test questions and answers, please press Ctrl + F to find your desired answers of the test questions.

1. Which of the following will return a User object when used with a model which deals with a table named User?
 Answers: • User.find
 2. 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.
 3. What is the best way to get the current request URL in Rails?
 Answers: • request.url
 4. 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.
 5. Which of the following commands adds the data model info to the model file?
 Answers: • generate model
 6. Which of the following HTML template languages are supported by Ruby?
 Answers: • Embedded Ruby
 7. 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.
 8. What is the output of the following code?
 Answers: • testtesttesttesttest
 9. 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.
 10. What is the difference between _url and _path while being used in routes?
 Answers: • _url is absolute while _path is relative.
 11. 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 %>
 12. 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: • None of these
 13. 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.
 14. 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.
 15. Which of the following is the correct way to know the Rails root directory path?
 Answers: • Rails.root
 16. 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
 17. 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
 18. 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.
 19. where we use attr_accessor and attr_accessible in rails ?
 Answers: • model
 20. Given the following code, where is the "party!" method available?
 module PartyAnimal
 def self.party!
 puts "Hard! Better! Faster! Stronger!"
 class Person
 include PartyAnimal
 Answers: • PartyAnimal.party!
 21. Which part of the MVC stack does ERB or HAML typically participate in?
 Answers: • View
 22. Which of the following items are stored in the models subdirectory?
 Answers: • database classes
 23. What is the output of the following code in Ruby?
 x= "A" + "B"
 puts x
 y= "C" << "D"
 puts y
 Answers: • AB CD
 24. Which gem is used to install a debugger in Rails 3?
 Answers: • gem "ruby-debug19"
 25. What exception cannot be handled with the rescue_from method in the application controller?
 class ApplicationControllers < ActionController::Base
 rescue_from Exception, with: error_handler
 Answers: • Server errors
 26. What component of Rails are tested with unit tests?
 Answers: • Models
 27. Which of the following replaced the Prototype JavaScript library in Ruby on Rails as the default JavaScript library?
 Answers: • jQuery
 28. 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.
 29. What is green-threading?
 Answers: • When threads are emulated by a virtual machine or interpreter.
 30. Which of the following assertions are used in testing views?
 Answers: • assert_select_encoded
 31. Is an AJAX call synchronous or asynchronous?
 Answers: • Either; it is configurable
 32. Which of the following commands will clear out sample users from the development database?
 Answers: • rake db:reset
 33. 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.
 34. 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
 35. Which of the following is the correct way to skip ActiveRecords in Rails 3?
 Answers: • Use option -O while generating application template.
 36. Which of the following is the default way that Rails seeds data for tests?
 Answers: • Fixtures
 37. Which of the following options, when passed as arguments, skips a particular validation?
 Answers: • :validate => false
 38. What declaration would you use to set the layout for a controller?
 Answers: • layout 'new_layout'
 39. What is the output of the following code?
 puts "aeiou".sub(/[aeiou]/, '*')
 Answers: • *eiou
 40. 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
 41. 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.
 42. Which of the following methods is used to check whether an object is valid or invalid?
 Answers: • .valid? and .invalid?
 43. 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)
 44. Which of the following is the correct syntax for an input field of radio buttons in form_for?
 Answers: • <%= f.radio_button :contactmethod, 'sms' %>
 45. 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>
 46. In order to enable locking on a table, which of the following columns is added?
 Answers: • lock_version column
 47. If a float is added to an integer, what is the class of the resulting number? i.e. 1.0 + 2
 Answers: • Float
 48. 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
 49. Which of the following will disable browser page caching in Rails?
 Answers: • expire_page(:controller => 'products', :action => 'index')
 50. 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
 51. Consider the following code snippet:
 def index
 The corresponding index.html.erb view is as following:
 <title>Ruby on Rails sample application | <%=@title%></title>
 Which of the following options is correct?
 Answers: • The HTML page will render with the title: Ruby on Rails sample application |.
 52. Unit tests are used to test which of the following components of Ruby on Rails?
 Answers: • Models
 53. If a controller is named "Users", what would its helpers module be called?
 Answers: • UsersHelper
 54. Which of the following serves as a structural skeleton for all HTML pages created?
 Answers: • application.html.erb
 55. Which of the following statements is incorrect?
 Answers: • Rails does not support ODBC connectivity.
 56. What is the Singleton design pattern?
 Answers: • A class for which there is only ever one instance.
 57. 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.
 58. What does REST stand for?
 Answers: • REpresentational State Transfer
 59. 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
 60. 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.
 61. When a new controller named "admin2" is created, the JS and the CSS files are created in:
 Answers: • assets
 62. 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.
 63. Which of the following is not a built-in Rails caching strategy used to reduce database calls?
 Answers: • Query Caching
 64. In a Rails application, the developmental and production configuration are stored in the:
 Answers: • config/environment folder
 65. 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.
 66. Which of the following correctly handles the currency field?
 A) add_column :items, :price, :decimal, :precision => 8, :scale => 2
 B) add_money :items, :price, currency: { present: false }
 Answers: • A
 67. 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'
 68. 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.
 69. Which of the following validations in Rails checks for null fields?
 Answers: • validates_presence_of
 70. Using ERB for views, what filename should be given to a partial called 'login'?
 Answers: • _login.html.e
 71. What is output of following statements?
 1) "".nil? == "".empty? && "".blank? == "".empty?
 2) !"".nil? == "".empty? && "".blank? == "".empty?
 3) nil.nil? == nil.empty? && nil.blank? == nil.empty?
 4) !"".blank? == "".present?
 5) "".any? == !"".empty?
 6) " ".blank? == " ".empty?
 Answers: • 1) false 2) true 3) NoMethodError: undefined method `empty?' for nil:NilClass 4) true 5) NoMethodError: undefined method `any?' for "":String 6) false
 72. 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.
 73. Which of the following controller actions (by default) are best suited to handle the GET HTTP request?
 Answers: • index
 74. 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.
 75. Which of the following is true about writing tests for a Ruby on Rails application?
 Answers: • All of these.
 76. What is the behavior of class variables with subclasses?
 Answers: • Class variables are shared between between all classes in the hierarchy.
 77. 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
 78. Consider the following information for a User view:
 user_path named route with value "/users/"
 @user = 1
 Now, consider the following code in the HTML erb template:
 <%= link_to user_path(@user), "Angel" %>
 What will be the HTML output of this code?
 Answers: • a href='Angel'>/users/1</a
 79. If a model called BlogComment is defined, what would its DB table be called?
 Answers: • blog_comments
 80. What is the output of the following code?
 $val = 20
 print "Sample Text\n" if $val
 Answers: • Sample Text
 81. Which of the following options will disable the rendering of the view associated with a controller action?
 Answers: • render :layout=>false
 82. The =~ operator is used to do inline Regular Expression matching, for instance:
 "function" =~ /fun/
 "function" =~ /dinosaurs/
 What are possible return values for the =~ matcher?
 Answers: • nil, 0, and any positive integer
 83. Which of the following options is used to create a form HTML in the erb files?
 Answers: • form_for
 84. Which of the following actions is fired by default when a new controller is created?
 Answers: • indexnijkkoooi,

No comments:

Post a Comment