Хотите пройти тесты на Upwork на хороший результат?
Подавайте заявку и мы поможем Вам это сделать!

Do You want to pass tests on Upwork with good scores?
Leave the request and we will help You to do that!

Ruby on Rails Test 2017

Share on RedditPin on PinterestEmail this to someoneShare on TumblrShare on LinkedInShare on Google+Tweet about this on TwitterShare on FacebookShare on VK

Мы не гарантируем правильность всех предоставленных ответов.


63 Test Questions:

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

Answers:

• 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.

Answers:

• @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

Answers:

• 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?

Answers:

• 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?

Answers:

• :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.

Answers:

• 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.

Answers:

• 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?

Answers:

• 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?

Answers:

• 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.

Answers:

• 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?

Answers:

• 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?

Answers:

• 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?

Answers:

• form_for
• create_form
• form_do
• form

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

Answers:

• UsersHelper
• UserControllerHelper
• UserHelp

15. What is the Singleton design pattern?

Answers:

• 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:

Answers:

• controllers
• helpers
• assets
• views

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

Answers:

• 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?

Answers:

• 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.

Answers:

• assets
• vendor
• jobs
• channels
• services

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

Answers:

• CodeClimate
• Brakeman
• Rubocop
• SimpleCov

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

Answers:

• 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.

Answers:

• 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?

Answers:

• 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?

Answers:

• <%= 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.

Answers:

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

26. What is TDD is rails3?

Answers:

• 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.

Answers:

• @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?

Answers:

• 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.

Answers:

• 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 = {})

Answers:

• :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?

Answers:

• Script
• Component
• Data
• View

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

Answers:

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

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

Answers:

• 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?

Answers:

• 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]

Answers:

• 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?

Answers:

• 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.

Answers:

• 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»?

Answers:

• «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.

Answers:

• <% 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?

Answers:

• 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?

Answers:

• .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.

Answers:

• 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?

Answers:

• 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
}

Answers:

• 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?

Answers:

• 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.

Answers:

• 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?

Answers:

• 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?

Answers:

• _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?

Answers:

• views
• template
• layout
• partial

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

Answers:

• lock_version
• optimistic_version
• lock_versions
• lock

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

Answers:

• 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?

Answers:

• 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?

Answers:

• plugin
• module
• mixin
• class

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

Answers:

• True
• False

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

Answers:

• type casting error
• test5
• 5
• testtesttesttesttest

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

Answers:

• Gemfile
• Rakefile
• config
• bundle

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

Answers:

• 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)

Answers:

• 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 ________________

Answers:

• content_type
• layout
• location
• formats
• language

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

Answers:

• view
• show
• render
• partial

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

Answers:

• 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?

Answers:

• validates_associated
• confirmation
• acceptance
• associate_validated

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

Answers:

• 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

  • Igor_Botvinnikov

    Спасибо!