| 
									
										
										
										
											2015-12-01 17:40:37 +03:00
										 |  |  | require 'yaml' | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | module SpecSupport | 
					
						
							| 
									
										
										
										
											2015-12-01 17:40:37 +03:00
										 |  |  |   ROOT = File.join(__dir__, '../../') | 
					
						
							| 
									
										
										
										
											2016-01-19 13:36:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def self.blank_file | 
					
						
							|  |  |  |     File.join(ROOT, 'spec/support/templates/blank_file') | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.tmp_dir | 
					
						
							|  |  |  |     File.join(ROOT, 'tmp/') | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-12-01 17:40:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def self.db_params | 
					
						
							| 
									
										
										
										
											2015-12-10 01:24:23 +03:00
										 |  |  |     @db_params ||= begin | 
					
						
							| 
									
										
										
										
											2015-12-01 17:40:37 +03:00
										 |  |  |       conf = config['mongo'] | 
					
						
							|  |  |  |       db_name = conf.fetch(:db) | 
					
						
							|  |  |  |       [db_name, conf[:host], conf[:port], conf[:user], conf[:password]] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.db | 
					
						
							|  |  |  |     unless @db | 
					
						
							| 
									
										
										
										
											2015-11-20 18:31:54 +03:00
										 |  |  |       require 'mongo' | 
					
						
							| 
									
										
										
										
											2015-12-01 17:40:37 +03:00
										 |  |  |       db_name, host, port, user, password = db_params | 
					
						
							|  |  |  |       @db = MongoClient.new(host, port).db(db_name) | 
					
						
							|  |  |  |       @db.authenticate(user, password) unless user.nil? or password.nil? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     @db | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.config | 
					
						
							|  |  |  |     @config ||= begin | 
					
						
							|  |  |  |       config_file = ENV['RSPEC_CONFIG_PATH'] || File.join(ROOT, 'spec/support/config.yml') | 
					
						
							|  |  |  |       if File.exists?(config_file) | 
					
						
							|  |  |  |         YAML.load_file(config_file) | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         raise "There is no config file: '#{config_file}'" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-11-20 18:31:54 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-19 13:36:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def self.root | 
					
						
							|  |  |  |     File.join(__dir__, '../../') | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | end |