null+****@clear*****
null+****@clear*****
Mon Feb 27 10:34:54 JST 2012
SUZUKI Miho 2012-02-27 10:34:54 +0900 (Mon, 27 Feb 2012) New Revision: ac2dab30716e6fdf11ddbcd45cfba6175dbd6a9f Merged 5e13d76: Merge pull request #55 from logaling/fix-loga-config Log: fix error occured if logaling_home not found Modified files: lib/logaling/command/application.rb spec/logaling/command_spec.rb Modified: lib/logaling/command/application.rb (+17 -11) =================================================================== --- lib/logaling/command/application.rb 2012-02-27 10:02:19 +0900 (b475ef7) +++ lib/logaling/command/application.rb 2012-02-27 10:34:54 +0900 (0d3400e) @@ -119,17 +119,23 @@ module Logaling::Command say "#{@config.glossary} is not yet registered." end - desc 'config [KEY] [VALUE] [--global(optional)]', 'Set config.' - method_option "global", type: :boolean, default: false - def config(key, value) - config_path = options["global"] ? File.join(@logaling_home, "config") : @project_config_path - config = Logaling::Config.load(config_path) - config.add(key, value) - config.save(config_path) - say "Successfully set config." - rescue Logaling::CommandFailed => e - say e.message - end + desc 'config [KEY] [VALUE] [--global(optional)]', 'Set config.' + method_option "global", type: :boolean, default: false + def config(key, value) + if options["global"] + FileUtils.mkdir_p(@logaling_home) unless File.exist?(@logaling_home) + config_path = File.join(@logaling_home, "config") + else + raise Logaling::CommandFailed, "Can't found .logaling" unless @project_config_path + config_path = @project_config_path + end + config = Logaling::Config.load(config_path) + config.add(key, value) + config.save(config_path) + say "Successfully set config." + rescue Logaling::CommandFailed => e + say e.message + end desc 'add [SOURCE TERM] [TARGET TERM] [NOTE(optional)]', 'Add term to glossary.' def add(source_term, target_term, note='') Modified: spec/logaling/command_spec.rb (+33 -0) =================================================================== --- spec/logaling/command_spec.rb 2012-02-27 10:02:19 +0900 (22ee439) +++ spec/logaling/command_spec.rb 2012-02-27 10:34:54 +0900 (ef8dcb2) @@ -220,6 +220,39 @@ describe Logaling::Command::Application do FileUtils.remove_entry_secure(global_config, true) end end + + context 'when logaling_home not exists' do + context 'with argument "target-language"' do + before do + command.new('spec', 'en') + FileUtils.remove_entry_secure(@logaling_home, true) + command.config("target-language", "fr") + end + + it 'should overwrite target-language' do + should include "--target-language fr" + end + end + + context 'with argument "--global" and "target-language"' do + before do + command.options = base_options.merge("global" => true) + command.new('spec', 'en') + FileUtils.remove_entry_secure(@logaling_home, true) + command.config("target-language", "ja") + end + + subject { File.read(global_config) } + + it 'should create {logaling_home}/config and write target-language' do + should include "--target-language ja" + end + + after do + FileUtils.remove_entry_secure(global_config, true) + end + end + end end describe '#add' do