magellan-rails 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bab654b4f481e42231eabc304585074524037978
4
- data.tar.gz: 513e1bfc85306e65ed3d560f045b31dedf5c45c2
3
+ metadata.gz: aff59ea017fc9a24aed8995129eda046534287d6
4
+ data.tar.gz: 2f581b6c7f596a8ed0a62127258e84891f849c5f
5
5
  SHA512:
6
- metadata.gz: 374417907f0e88bf1286d112a2a4b038e9722dfef5300a039730f07e67baccf05af7c041120d6b68b161613a9fc866244430e832ccbae8df4e64194c4fd3db5e
7
- data.tar.gz: 71a41a879cabbe907014f13625839dccaf696d2b84e0347f2f69c8158d21b921d51959731901253234a7aa6751d03fe2a750bbd52b165ed0ebd0e41fafa4bd48
6
+ metadata.gz: e837a14ddebe97bc16d438dd825ca1a07619d676fa91a95f119002f35176d6e0ceab67301fd7ea492d4beca5b46c52fd5918039bc05ce65d232df5fb8ecf4652
7
+ data.tar.gz: 49323c5a936fbbced6916b148cf958d109935e5fd10933369ae4dd48286b8ae87e9708f848ee81eb4923652a29f72d942939b81c82308c700c1f89d403c97f11
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Rails
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -1,11 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'magellan/rails'
3
+ require "yaml"
3
4
 
4
5
  class Magellan::Subscriber::RoutingError < StandardError
5
6
  end
6
7
 
7
8
  class Magellan::Subscriber::Mapper
8
- def initialize(map_file_path=Rails.root.join("config/subscribes.yml"))
9
+ def self.default_mapper_file
10
+ map_file_path = ::Rails.root.join("config/subscriptions.yml")
11
+ unless map_file_path.readable?
12
+ map_file_path = ::Rails.root.join("config/subscribes.yml")
13
+ end
14
+ map_file_path.to_path
15
+ end
16
+
17
+ def initialize(map_file_path=self.class.default_mapper_file)
9
18
  # テストのため nil で初期化できるようにしています
10
19
  if map_file_path
11
20
  @config_file = map_file_path.to_s
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
 
5
5
  require "magellan/subscriber"
6
6
  require "magellan/subscriber/mapper"
7
+ require "rails"
7
8
 
8
9
  describe Magellan::Subscriber::Mapper do
9
10
 
@@ -259,6 +260,50 @@ describe Magellan::Subscriber::Mapper do
259
260
  end
260
261
  end
261
262
  end
263
+ end
262
264
 
265
+ describe "#initialize" do
266
+ before do
267
+ @tmpdir = Dir.mktmpdir
268
+ @subscribes_file = File.join(@tmpdir, "subscribes.yml")
269
+ @subscriptions_file = File.join(@tmpdir, "subscriptions.yml")
270
+ @root = double "Rails.root"
271
+ allow(::Rails).to receive(:root).and_return(@root)
272
+ allow(@root).to receive(:join).with("config/subscribes.yml").and_return(Pathname(@subscribes_file))
273
+ allow(@root).to receive(:join).with("config/subscriptions.yml").and_return(Pathname(@subscriptions_file))
274
+ @prepare_subscribes_file = ->() { open(@subscribes_file, "w") { |f| f.puts "t: verbs#action" } }
275
+ @prepare_subscriptions_file = ->() { open(@subscriptions_file, "w") { |f| f.puts "t: nouns#action" } }
276
+ end
277
+ after do
278
+ FileUtils.rm_rf(@tmpdir)
279
+ end
280
+ context "subscribes.yml exists" do
281
+ before do
282
+ @prepare_subscribes_file.call
283
+ end
284
+ it "use subscribes.yml" do
285
+ mapper = Magellan::Subscriber::Mapper.new
286
+ expect(mapper.map_action("t")).to eql([["VerbsSubscriber", "action"]])
287
+ end
288
+ end
289
+ context "subscriptions.yml exists" do
290
+ before do
291
+ @prepare_subscriptions_file.call
292
+ end
293
+ it "use subscriptions.yml" do
294
+ mapper = Magellan::Subscriber::Mapper.new
295
+ expect(mapper.map_action("t")).to eql([["NounsSubscriber", "action"]])
296
+ end
297
+ end
298
+ context "both subscribes.yml and subscriptions.yml exists" do
299
+ before do
300
+ @prepare_subscribes_file.call
301
+ @prepare_subscriptions_file.call
302
+ end
303
+ it "use subscriptions.yml" do
304
+ mapper = Magellan::Subscriber::Mapper.new
305
+ expect(mapper.map_action("t")).to eql([["NounsSubscriber", "action"]])
306
+ end
307
+ end
263
308
  end
264
309
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuuki Noguchi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties