Ruby On Rails Test Answers 2019


Share Ruby On Rails Test Answers

Posted on June 7, 2019


63 Test Questions:

1. For the String class, what’s the difference between «#slice» and «#slice!»?

• None, «#slice» is just an alias for «#slice!».
• There is no «#slice!» method in Ruby on Rails.
• «#slice» returns a new object, «#slice!» destructively updates — mutates — the object’s value.

2. How to pass variable “projects” into ERB template from controller?
Note: There may be more than one right answer.

• @projects = Project.all
• render locals: { projects: Project.all }
• render projects: Project.all
• render :index, projects: Project.all

3. How to permit nester attributes in Rails controllers for such model?
class User
has_one :profile
accepts_nested_attributes_for :profile
end

• params.require(:user).permit(:email, profile: [:id, :_destroy])
• params.require(:user).permit(:email, profile: {:id, :_destroy})
• params.require(:user).permit(:email, profile_attributes: [:id, :_destroy])
• params.require(:user).permit(:email, profile_attributes: {:id, :_destroy})

4. The has_one association supports following options?

• A):autoload, :validated
• B):class_id, : foreign_name
• C):dependent, :primary_key, :source_type
• D):foreign_key, :inverse_of, :source
• E)C,D

5. Which of these option for “dependent” not exists in Rails?

• :destroy
• :nullify
• :restrict_with_exception
• :restrict_with_error
• All of these options exist

6. Select a True statements?
Note: There may be more than one right answer.

• ActiveRecord ,Talks to the database system Creates Ruby objects modeled on the database tables
• ActionController ,Manipulates ActiveRecord objects Loads data into variables for use in ActionView templates Uses CGI library to process form data held in CGI variables
• ActionView ,Fills ERb templates with data processed by ActionController Hands off the resulting HTML to the Web server
• Support libraries, ActiveRecord ActionWebServices ActionMail
• All of the above

7. What are the Available callbacks?
Note: There may be more than one right answer.

• around_enqueue
• after_enqueue
• before_perform
• around_perform
• None of the above

8. How you can create a many-to-many relationship in model «User» between “User” and “Project” through a third model?

• has_many :project_users, through: :projects
has_many :projects
• has_many :project_users
has_many :projects, through: :project_users
• has_many :project_users, source: :projects
• has_many :projects, source: :project_users

9. Which of the following is the correct way to add a field in a signup that is not present in the User Model?

• Use a nested attribute with the Devise Model.
• Create a Controller.
• It will throw Activerecord::UnknownAttributeError if try to add the other field.
• It will throw Activerecord::UnknownModelField if try to add the other field.

10. Which of the following is not true about log levels in Ruby on Rails?
Note: There may be more than one right answer.

• The available log levels are: :debug, :info, :warn, :error, and :fatal, corresponding to the log level numbers from 1 up to 5 respectively.
• To check the current log level, the Rails.logger.level method has to be called.
• By default, each log is created under Rails.root/log/ and the log file name is environment_name.log.
• The default Rails log level is error in production mode and debug in development and test mode.

11. Which of the following will change a Rails 3 app to run in production mode?

• rails s -p production
• rails s -e production
• rails s production
• rails s -p PRODUCTION

12. What is the purpose of the model in an MVC architecture framework such as Ruby on Rails?

• The model houses all the code that relates to data.
• The model contains the minimum amount of code to display data.
• Methods in the model can be directly accessed in Rails views.
• The model performs parsing user requests, data submissions, cookies, sessions and other web browser operations.

13. Which of the following options is used to create a form HTML in the erb files?

• form_for
• create_form
• form_do
• form

14. If a controller is named «Users», what would its helpers module be called?

• UsersHelper
• UserControllerHelper
• UserHelp

15. What is the Singleton design pattern?

• A class for which there is only ever one instance.
• A single feature application, intended to enhance usability by keeping things simple.
• A class which is never instanced, but acts as a container for methods which are used by it’s subclasses.

16. When a new controller named «admin2» is created, the JS and the CSS files are created in:

• controllers
• helpers
• assets
• views

17. Which of the following statements regarding models in Ruby on Rails is correct?

• The page HTML is generated by models.
• The fetching of data from database is performed by models.
• The web requests sent by the browser is handled by models.
• The routing configuration is done by models.

18. Which of the following command you will use Updates Ruby to the latest version?

• gem update
• gem update –system
• gem update —system
• All of the above

19. Which of these folders do not exist in folder “app” in Rails 5?
Note: There may be more than one right answer.

• assets
• vendor
• jobs
• channels
• services

20. Which of these tools are for checking Ruby code styling?

• CodeClimate
• Brakeman
• Rubocop
• SimpleCov

21. THE CONTENTS OF ACTIONPACK ActionView and ActionController are bundled together as ActionPack because in the MVC structure?

• A)M
• B)V
• C)C
• D)B and C

22. What are the asset tag helpers available in Rails?
Note: There may be more than one right answer.

• auto_discovery_link_tag
• javascript_link_tag
• stylesheet_link_tag
• image_tag
• All of the above

23. Which of the following open directly is correct about Open URI?

• open(‘http://www.example.com’)
{
data results => data.read
}

• open(‘http://www.example.com’)
{
| data | results = data.read
}

• open(‘http://www.example.com’)
{
data | results = data.open
}

• open(http://www.example.com)
{
data => results = data.read
}

24. Which of the following code is correct about Creating links?

• <%= link_to “Button”, {:action => “action_name”,:id => product} :confirm => “some text here” %>
• <%= link_to “Button”, {:action => “action_name”, :id => product}, :confirm => “some text here” %>
• <%= link_to “Button”, {:action => “action_name”,id => product},confirm => “some text here” %>
• <%= link_to “Button”, {:action = “action_name”,:id = product},:confirm = “some text here” %>

25. Following methods trigger validations, and will save the object to the database only if the object is valid?
Note: There may be more than one right answer.

• create
• create!
• update
• update!
• None of the above

26. What is TDD is rails3?

• TDD directs focus on testing.
• TDD directs focus on behavior and specification.
• Both A and B
• None of them is correct

27. Which of the following instance variables in your functional tests?
Note: There may be more than one right answer.

• @controller — The controller processing the request
• @request — The request object
• @response — The response object
• @posts – The post object

28. How to disable protection of CSRF attacks for API requests?

• protect_from_forgery with: :exception
• protect_from_forgery with: :api_ingore
• protect_from_forgery with: :null_session
• protect_from_forgery with: :ignore

29. Which of these filters do no exist in Rails controller?
Note: There may be more than one right answer.

• before_action
• after_action
• skip_action_callback
• skip_before_callback
• skip_after_callback

30. The send_data method has the following options?
send_data(data, options = {})

• :filename Suggests a filename for the browser to use
• :type Specifies an HTTP content type. Defaults to ‘application/octet-stream’
• :disposition Specifies whether the file will be shown inline or downloaded. Valid values are inline and attachment (default)
• :status Specifies the status code to send with the response. Defaults to ‘200 OK’
• All of the above

31. A controller is a server-side _____ of Rails that responds to external requests from the web server to the application?

• Script
• Component
• Data
• View

32. Which of these routes not generated by “resource :user”?

• GET /user
• GET /user/1
• GET /user/new
• PATCH /user

33. How is possible to create combined unique index for two fields?

• add_index :project_users, :user_id, combine_with: :project_id, unique: true
• add_index :project_users, [:user_id, :project_id], unique: true
• add_index :project_users, :user_id, unique: true
add_index :project_users, :project_id, unique: true
• add_index :project_users, :user_id, unique: true do
add_index :project_users, :project_id, unique: true
end

34. The following methods skip validations, and will save the object to the database regardless of its validity?

• A)update_all, update_attribute,update_column
• B)decrement_counter, decrement!
• C)increment!, update_counters
• D)increment_count, update_tables
• E)A,B,C

35. What is the purpose of using below code in filter_parameter_logging.rb?
Rails.application.config.filter_parameters += [:password]

• Remove “password” from input parameters
• Disallow to send “password” via GET request
• Hide «password» parameter in applications logs
• Automatically trim whitespaces of “password” parameter

36. Which of these methods catch Exception in Rails controllers?

• raise_from
• rescue_from
• catch_raise
• catch_rescue

37. Which of these statements about Ruby on Rails 5 are false?
Note: There may be more than one right answer.

• Added ActionCable
• Rails API gem merged in core of Rails
• Added ApplicationRecord top-level model
• Relation «has_one» is required by default
• Terminal command «rails» replaced by «rake»

38. What is the difference between «has_many :through» and «has_and_belongs_to_many»?

• «has_many :through» requires an additional table in the database, whereas «has_and_belongs_to_many» does not
• «has_many :through» requires an additional data model, whereas «has_and_belongs_to_many» does not
• You should use «has_and_belongs_to_many» if you need validations, callbacks or extra attributes on the join model
• No differences between these relations

39. Which of the following code is correct about Partials and Collections?
Note: There may be more than one right answer.

• <% for article in @articles %>
<%= render :partical =>’article’, :object => article %>
<% end %>
• <% render :partial => ‘article’, :collection => @articles %>
• <% for article @articles %>
<%= render :partical =>’article’, object => article %>
<% end %>
• <% render :partial => ‘article’, collection => @articles %>

40. Which of the following statements is true regarding the find_or_create method in Ruby on Rails?

• It can find multiple arguments by using Model.find_or_create_by_name(‘name here’). It will first find the record and if it doesn’t exist it will create it.
• It cannot be used in Ruby on Rails.
• It is similar to the find query.
• It is similar to the create query.

41. Which of these files determine Ruby version and gemset for RVM library?

• .rb-version, .rb-gemset
• .ruby-version, .ruby-gemset
• .version, .gemset
• .rvm-version, .rvm-gemset

42. What are the CGI Library?
Note: There may be more than one right answer.

• CGI data processing routines
• Parses incoming form data
• Part of the Ruby standard library
• None of the above

43. Which of these is not a valid Bundler command?

• bundle exec
• bundle console
• bundle config
• bundle deps

44. Which of these model methods will be generated by this code?
enum state: {
blocked: 0,
active: 1
}

• Model.states
• blocked?
• active!
• All of these
• None of these

45. Which of these options is right to create default scope of model in Rails?

• scope, -> { order(:position) }
• scope :default, -> { order(:position) }
• default_scope -> { order(:position) }
• default_scope, -> { order(:position) }

46. Which of these files are located by default in «config” directory? (check any that apply)
Note: There may be more than one right answer.

• application.rb
• config.ru
• environment.rb
• assets.rb

47. Which of the following is not an advantage of using an integrated development environment (IDE) for Rails ,compared with using a simple text editor?

• Automated code analysis
• Assisted refactoring
• Smaller memory footprint
• Integrated version control

48. What is the difference between _url and _path while being used in routes?

• _url is absolute while _path is relative.
• _path is relative while _path is absolute.
• _path is used in controllers while _url is used in views.
• _path is used in views while _url is used in controllers.

49. Which declaration can be used to override the default layout conventions in your controllers?

• views
• template
• layout
• partial

50. In order to use optimistic locking, the table needs to have a column called ___________ of type integer.

• lock_version
• optimistic_version
• lock_versions
• lock

51. Which method is used in views to prevent CSRF attack?

• csrf_prevent_meta_tag
• csrf_protect_meta_tag
• csrf_meta_tag
• csrf_tag

52. Which of the following rake commands can be used to load a schema.rb file into the database?

• rake db:schema:dump
• rake:db:schema:load
• rake:db:migrate
• rake:db:schema:clone

53. Which of the following is used to achieve multiple inheritance in Ruby?

• plugin
• module
• mixin
• class

54. The asset tag helpers do not verify the existence of the assets at the specified locations.

• True
• False

55. What is the output of the following code?
&amp;quot;test&amp;quot;*5

• type casting error
• test5
• 5
• testtesttesttesttest

56. Which file contains the Gem requirements of an RoR App?

• Gemfile
• Rakefile
• config
• bundle

57. What is the SQL equivalent of following code?
user=User.first(3)

• SELECT *from users where users.id=3
• SELECT *from users ORDER BY users.id DESC limit 3
• SELECT *from users ORDER BY users.id ASC limit 3
• SELECT *from users limit 2

58. What is the SQL equivalent of following code?
user=User.take(3)

• SELECT *from users limit 1
• SELECT *from users where users.id=3
• SELECT *from users limit 3
• SELECT *from users limit 2

59. render method does not accept ________________

• content_type
• layout
• location
• formats
• language

60. Which method is used to render partial templates as part of a view?

• view
• show
• render
• partial

61. Which of the following loops is not supported by Ruby?

• While
• For
• Unless
• Untill

62. Which helper should be used when your model has association with other models and they also need to be validated?

• validates_associated
• confirmation
• acceptance
• associate_validated

63. What is the difference between find() and find_by_id() method?

• find_by_id() will raise an error in case record does not exist for a given primary key whereas find() will not raise an error and will return nil
• find() will raise an error in case record does not exist for a given primary key whereas find_by_id() will not raise an error and will return nil
• Both are same
• None of the above