cequel-migrations-rails 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Cequel
2
2
  module Migrations
3
3
  module Rails
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
6
6
  end
7
7
  end
@@ -10,8 +10,20 @@ module Cequel
10
10
  db.execute(cql_string)
11
11
  end
12
12
 
13
+ def self.cequel_conf_path
14
+ File.join(::Rails.root, "config", "cequel.yml")
15
+ end
16
+
17
+ def self.cequel_conf_file
18
+ File.open(self.cequel_conf_path)
19
+ end
20
+
21
+ def self.cequel_conf
22
+ YAML::load(self.cequel_conf_file)
23
+ end
24
+
13
25
  def self.cequel_env_conf
14
- YAML::load(File.open(File.join(::Rails.root,"config", "cequel.yml")))[::Rails.env]
26
+ self.cequel_conf[::Rails.env]
15
27
  end
16
28
 
17
29
  private
@@ -25,7 +37,7 @@ module Cequel
25
37
 
26
38
  def thrift_options
27
39
  if self.class.cequel_env_conf['thrift']
28
- return self.class.cequel_env_conf['thrift'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
40
+ return self.class.cequel_env_conf['thrift'].inject({}) { |obj,(k,v)| obj[k.to_sym] = v; obj }
29
41
  else
30
42
  return {}
31
43
  end
@@ -0,0 +1,16 @@
1
+ development:
2
+ host: 'capture.services.dev:9160'
3
+ keyspace: capture_api_dev
4
+ strategy_class: SimpleStrategy
5
+ strategy_options:
6
+ replication_factor: 1
7
+ thrift:
8
+ connect_timeout: 5
9
+ timeout: 10
10
+ test:
11
+ host: 'capture.services.dev:9160'
12
+ keyspace: capture_api_test
13
+ strategy_class: SimpleStrategy
14
+ strategy_options:
15
+ replication_factor: 1
16
+ thrift: ~
@@ -8,7 +8,7 @@ describe Cequel::Migration do
8
8
  describe "#new" do
9
9
  it "create a cassandra-cql database connection for the host & keyspace specified in the environment's config" do
10
10
  migration_class.stub(:cequel_env_conf).and_return({ 'host' => 'somehost', 'keyspace' => 'somekeyspace' })
11
- CassandraCQL::Database.should_receive(:new).with('somehost', { :keyspace => 'somekeyspace' })
11
+ CassandraCQL::Database.should_receive(:new).with('somehost', { :keyspace => 'somekeyspace' }, {})
12
12
  migration
13
13
  end
14
14
  end
@@ -22,4 +22,106 @@ describe Cequel::Migration do
22
22
  migration.execute("some cql string")
23
23
  end
24
24
  end
25
+
26
+ describe ".cequel_conf_path" do
27
+ it "returns the path to the cequel conf file" do
28
+ ::Rails.stub(:root).and_return('/foo/bar')
29
+ migration_class.cequel_conf_path.should eq('/foo/bar/config/cequel.yml')
30
+ end
31
+ end
32
+
33
+ describe ".cequel_conf_file" do
34
+ it "returns the file object of the file at the cequel_conf_path" do
35
+ conf_path = stub
36
+ conf_file = stub
37
+ migration_class.stub(:cequel_conf_path).and_return(conf_path)
38
+ File.should_receive(:open).with(conf_path).and_return(conf_file)
39
+ migration_class.cequel_conf_file.should eq(conf_file)
40
+ end
41
+ end
42
+
43
+ describe ".cequel_conf" do
44
+ it "returns the hash result of YAML loading the cequel.yml conf file" do
45
+ conf_file = stub
46
+ conf_hash = stub
47
+ migration_class.stub(:cequel_conf_file).and_return(conf_file)
48
+ ::YAML.should_receive(:load).with(conf_file).and_return(conf_hash)
49
+ migration_class.cequel_conf.should eq(conf_hash)
50
+ end
51
+ end
52
+
53
+ describe ".cequel_env_conf" do
54
+ it "gets the cequel conf" do
55
+ migration_class.should_receive(:cequel_conf).and_return({})
56
+ migration_class.cequel_env_conf
57
+ end
58
+
59
+ it "grabs the Rails.env section of the config" do
60
+ conf = mock
61
+ ::Rails.stub(:env).and_return('blue')
62
+ conf.should_receive(:[]).with('blue')
63
+ migration_class.stub(:cequel_conf).and_return(conf)
64
+ migration_class.cequel_env_conf
65
+ end
66
+
67
+ context "when the environment is found in the config" do
68
+ before do
69
+ ::Rails.stub(:root).and_return(File.expand_path('../../../fixtures', __FILE__))
70
+ ::Rails.stub(:env).and_return('development')
71
+ end
72
+
73
+ it "returns that environments portion of the config as a hash" do
74
+ migration_class.cequel_env_conf.should eq({
75
+ "host"=>"capture.services.dev:9160",
76
+ "keyspace"=>"capture_api_dev",
77
+ "strategy_class"=>"SimpleStrategy",
78
+ "strategy_options"=>{
79
+ "replication_factor"=>1
80
+ },
81
+ "thrift"=>{
82
+ "connect_timeout"=>5,
83
+ "timeout"=>10
84
+ }
85
+ })
86
+ end
87
+ end
88
+
89
+ context "when the environment is NOT found in the config" do
90
+ before do
91
+ ::Rails.stub(:root).and_return(File.expand_path('../../../fixtures', __FILE__))
92
+ ::Rails.stub(:env).and_return('nonexistentenvironment')
93
+ end
94
+
95
+ it "returns nil" do
96
+ migration_class.cequel_env_conf.should be_nil
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#thrift_options" do
102
+ context "when the environment is found in the config" do
103
+ before do
104
+ ::Rails.stub(:root).and_return(File.expand_path('../../../fixtures', __FILE__))
105
+ ::Rails.stub(:env).and_return('development')
106
+ end
107
+
108
+ context "when thrift options are found in the config" do
109
+ it "returns the thrift options as a hash" do
110
+ CassandraCQL::Database.stub(:new).and_return(stub.as_null_object)
111
+ migration.send(:thrift_options).should eq({:connect_timeout=>5, :timeout=>10})
112
+ end
113
+ end
114
+
115
+ context "when thrift options are NOT found in the config" do
116
+ before do
117
+ ::Rails.stub(:env).and_return('test')
118
+ end
119
+
120
+ it "returns an empty hash" do
121
+ CassandraCQL::Database.stub(:new).and_return(stub.as_null_object)
122
+ migration.send(:thrift_options).should eq({})
123
+ end
124
+ end
125
+ end
126
+ end
25
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cequel-migrations-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-05 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shearwater
@@ -98,6 +98,7 @@ files:
98
98
  - lib/generators/cequel/migration/templates/migration.rb
99
99
  - lib/generators/cequel/migrations/install/install_generator.rb
100
100
  - lib/generators/cequel/migrations/install/templates/cequel/migrate/.gitkeep
101
+ - spec/fixtures/config/cequel.yml
101
102
  - spec/lib/cequel-migrations-rails/cql_manager_spec.rb
102
103
  - spec/lib/cequel/migration_spec.rb
103
104
  - spec/spec_helper.rb
@@ -126,6 +127,7 @@ signing_key:
126
127
  specification_version: 3
127
128
  summary: A Rails plugin that provides migration support for Cequel.
128
129
  test_files:
130
+ - spec/fixtures/config/cequel.yml
129
131
  - spec/lib/cequel-migrations-rails/cql_manager_spec.rb
130
132
  - spec/lib/cequel/migration_spec.rb
131
133
  - spec/spec_helper.rb