From 5c3fbd3cb927957421e0c23be0f46de42b6073d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 9 Jan 2018 14:53:54 +0300 Subject: [PATCH] KBP-175 #time 1h change application_responder setting mechanism and code refactor for project initialization --- lib/cybele/generators/app_generator.rb | 28 +++++++++---------- lib/cybele/helpers/responders.rb | 5 ++-- spec/features/git_and_git_flow_spec.rb | 1 - spec/features/new_default_project_spec.rb | 5 ++-- spec/features/new_not_default_project_spec.rb | 1 - spec/support/responder_test_helper.rb | 2 +- .../controllers/hq/application_controller.rb | 1 + .../user/application_controller.rb | 1 + 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index bd561e8..eaa94b5 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -65,7 +65,7 @@ class AppGenerator < Rails::Generators::AppGenerator aliases: nil, default: false, group: :cybele, - desc: 'Skip view files. Default: don\'t skip' + desc: 'Skip view files. Default: don\'t skip. Dependent: haml, show-for, simple-form' class_option :skip_docker, type: :boolean, aliases: nil, @@ -295,28 +295,28 @@ def get_builder_class # :reek:TooManyStatements def ask_questions(options) say 'Ask cybele options', :green - option_with_ask_limited(:database, DATABASES) - option_with_ask_yes(:skip_create_database) - option_with_ask_yes(:skip_sidekiq) - option_with_ask_yes(:skip_simple_form) - option_with_ask_yes(:skip_show_for) - option_with_ask_yes(:skip_haml) - option_with_ask_yes(:skip_view_files) - option_with_ask_yes(:skip_docker) + option_with_ask_limited(options, :database, DATABASES) + option_with_ask_yes(options, :skip_create_database) + option_with_ask_yes(options, :skip_sidekiq) + option_with_ask_yes(options, :skip_simple_form) + option_with_ask_yes(options, :skip_show_for) + option_with_ask_yes(options, :skip_haml) + option_with_ask_yes(options, :skip_view_files) + option_with_ask_yes(options, :skip_docker) options.freeze dependency_control(options) end - def option_with_ask_yes(key) + def option_with_ask_yes(options, key) say "==> #{key.to_s.humanize}", :green say 'Type for answer yes: y|yes', :green say 'Type for answer no: n|no|any character', :yellow - @options = @options.merge(key => yes?('Ans :', :green)) + options.merge!(key => yes?('Ans :', :green)) end - def option_with_ask_limited(key, limits) - @options = @options.merge(key => ask("#{key.to_s.humanize} :", limited_to: limits)) + def option_with_ask_limited(options, key, limits) + options.merge!(key => ask("#{key.to_s.humanize} :", limited_to: limits)) end def dependency_control(selected_options) @@ -326,7 +326,6 @@ def dependency_control(selected_options) # :reek:TooManyStatements def arg_checker(selected_options, option, option_array) return if selected_options[option] - puts "#{option} dependency error!" failed = false option_array.each do |opt| if selected_options[opt] @@ -335,6 +334,7 @@ def arg_checker(selected_options, option, option_array) end end return unless failed + puts "#{option} dependency error!" puts puts 'See --help for more info' exit 0 diff --git a/lib/cybele/helpers/responders.rb b/lib/cybele/helpers/responders.rb index 11caf3d..8942aef 100644 --- a/lib/cybele/helpers/responders.rb +++ b/lib/cybele/helpers/responders.rb @@ -21,12 +21,11 @@ def replace_responders_file_contents replace_in_file 'app/controllers/application_controller.rb', 'respond_to :html', 'respond_to :html, :js, :json' + comment_lines 'app/controllers/application_controller.rb', + /self.responder = ApplicationResponder/ replace_in_file 'app/controllers/application_controller.rb', 'require "application_responder"', "require 'application_responder'" - replace_in_file 'app/controllers/application_controller.rb', - 'self.responder = ApplicationResponder', - 'self.responder = ApplicationResponder unless :devise_controller?' # Remove comments in locale/responders.yml remove_file 'config/locales/responders.en.yml', force: true copy_file 'config/locales/responders.tr.yml', 'config/locales/responders.tr.yml' diff --git a/spec/features/git_and_git_flow_spec.rb b/spec/features/git_and_git_flow_spec.rb index 3c0833f..56fb5f7 100644 --- a/spec/features/git_and_git_flow_spec.rb +++ b/spec/features/git_and_git_flow_spec.rb @@ -4,7 +4,6 @@ RSpec.describe 'Create new project without default configuration' do before do - drop_dummy_database remove_project_directory run_cybele(cybele_not_default_parameters) setup_app_dependencies diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index cf5ae57..9f46367 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -4,7 +4,6 @@ RSpec.describe 'Create new project with default configuration' do before(:all) do - drop_dummy_database remove_project_directory run_cybele('--skip-create-database') setup_app_dependencies @@ -220,10 +219,10 @@ expect(File).not_to exist(file_project_path('app/assets/stylesheets/application.css')) - application_stylesheets_file = content('app/assets/stylesheets/application.css.sass') + application_stylesheets_file = content('app/assets/stylesheets/application.sass') expect(application_stylesheets_file).to match('@import "bootstrap"') - hq_stylesheets_js_file = content('app/assets/stylesheets/hq/application.css.sass') + hq_stylesheets_js_file = content('app/assets/stylesheets/hq/application.sass') expect(hq_stylesheets_js_file).to match('@import "bootstrap"') application_js_file = content('app/assets/javascripts/application.js') diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 1423120..726242e 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -4,7 +4,6 @@ RSpec.describe 'Create new project without default configuration' do before(:all) do - drop_dummy_database remove_project_directory run_cybele(cybele_not_default_parameters) setup_app_dependencies diff --git a/spec/support/responder_test_helper.rb b/spec/support/responder_test_helper.rb index 6bc72c6..e038d40 100644 --- a/spec/support/responder_test_helper.rb +++ b/spec/support/responder_test_helper.rb @@ -17,7 +17,7 @@ def responder_test def controller_file_test controller_file = content('app/controllers/application_controller.rb') expect(controller_file).to match("^require 'application_responder'") - expect(controller_file).to match('self.responder = ApplicationResponder') + expect(controller_file).to match('# self.responder = ApplicationResponder') expect(controller_file).to match('respond_to :html, :js, :json') end diff --git a/templates/app_files/app/controllers/hq/application_controller.rb b/templates/app_files/app/controllers/hq/application_controller.rb index 529ed15..094e02f 100644 --- a/templates/app_files/app/controllers/hq/application_controller.rb +++ b/templates/app_files/app/controllers/hq/application_controller.rb @@ -3,6 +3,7 @@ class Hq::ApplicationController < ApplicationController before_action :set_audit_user layout 'hq/application' + self.responder = ApplicationResponder private diff --git a/templates/app_files/app/controllers/user/application_controller.rb b/templates/app_files/app/controllers/user/application_controller.rb index 8a7779c..97ef429 100644 --- a/templates/app_files/app/controllers/user/application_controller.rb +++ b/templates/app_files/app/controllers/user/application_controller.rb @@ -4,6 +4,7 @@ class User::ApplicationController < ApplicationController layout 'application' before_action :authenticate_user! before_action :set_user_time_zone + self.responder = ApplicationResponder protected