fixture_box 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efec83e114bb1aabedb7ede59d43ea64ac37b96d3c6d995fba438b082840409e
4
- data.tar.gz: 315e4c0d734ac5384c42dcbaa9cbea903de5eed8fcffb608f20cde928be3aeb6
3
+ metadata.gz: 1b7c97890a0ad1fa960247ad41245def5db7f6b3b7036d17936538255fcdcc57
4
+ data.tar.gz: b3a58fcf473b8b8a2242f19bacf9b18b2680c69dc6b6e4b6a9f9daa0426c7055
5
5
  SHA512:
6
- metadata.gz: fc59bc42eb9f6d7548e8678b803a80d9a29e8c9b52bfd81fef17ba4cea9ec3abfb87fe5ee72c2205b549bffbfd9e8349dd517f33d857fbad93f2aef1aca5bcb2
7
- data.tar.gz: dc65c3b9f1f2c7894856d6fab8fdd99241192765ca443998bc453d3ae12c28381acaec9a4091acc8e1a2e5c7a93bb3204e35c240ec43de21c2fd4645f33f1f1f
6
+ metadata.gz: 693099cb7e305d11e0c6260a1f9b8a3aed181c3e34edc08ea7b3b5f97c10c3656a7180bd419282e020d2da7e44fe55fe7626372bad013e1b5141560ac760cacf
7
+ data.tar.gz: 784dffda5d42a5c6f4548e2b1a524848c4e3176700fce3d7a9e9c2f81ec1f71375cb40fd067d7e3f137f940caba5eb0da58520f4a99baaa1a51d226bccc8e52a
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # FixtureBox
2
- Short description and motivation.
2
+ Dynamically creating ActiveRecord Fixtures.
3
3
 
4
4
  ## Usage
5
5
 
@@ -59,12 +59,15 @@ assert_equal 'Wagahai wa Neko de Aru', @fixture_box.books(:wagahai_wa_neko_de_ar
59
59
  assert_equal 'Natsume Soseki', @fixture_box.books(:wagahai_wa_neko_de_aru).author.name
60
60
 
61
61
  # Set the model class
62
+ assert_equal 'application/zip', @fixture_box.book_files(:wagahai_wa_neko_de_aru_zip).content_type
62
63
  assert_equal %w(application/zip application/x-expandedbook), @fixture_box.books(:wagahai_wa_neko_de_aru).files.pluck(:content_type)
63
64
 
64
65
  # Get all instances
65
66
  assert_equal ['Wagahai wa Neko de Aru', 'Ame ni mo Makezu'], @fixture_box.books.map(&:name)
66
67
  ```
67
68
 
69
+ See more at `test/fixture_box_test.rb`
70
+
68
71
  ## Installation
69
72
  Add this line to your application's Gemfile:
70
73
 
@@ -13,7 +13,7 @@ class FixtureBox
13
13
  decorated_class_names = {}
14
14
  data.each do |fixture_set_name, fixture_data|
15
15
  fixture_class = class_names[fixture_set_name] || fixture_set_name.to_s.classify.constantize
16
- decorated_fixture_set_name = fixture_set_name
16
+ decorated_fixture_set_name = decorate_fixture_set_name(fixture_set_name)
17
17
 
18
18
  decorated_fixture_set_names << decorated_fixture_set_name
19
19
  decorated_class_names[decorated_fixture_set_name] = fixture_class
@@ -31,10 +31,22 @@ class FixtureBox
31
31
 
32
32
  private
33
33
 
34
+ def fixture_set_name_prefix
35
+ "fixture_box:#{object_id}"
36
+ end
37
+
38
+ def decorate_fixture_set_name(fixture_set_name)
39
+ "#{fixture_set_name_prefix}:#{fixture_set_name}"
40
+ end
41
+
42
+ def accessor_name(decorated_fixture_set_name)
43
+ decorated_fixture_set_name.match(/^#{fixture_set_name_prefix}:(.+)$/).captures.first
44
+ end
45
+
34
46
  def setup_fixture_accessors
35
- @loaded_fixture_sets.each do |fixture_set_name, fixture_set|
36
- define_singleton_method(fixture_set_name) do |*fixture_names|
37
- fixture_names = @loaded_fixture_sets[fixture_set_name].fixtures.keys if fixture_names.empty?
47
+ @loaded_fixture_sets.each do |decorated_fixture_set_name, fixture_set|
48
+ define_singleton_method(accessor_name(decorated_fixture_set_name)) do |*fixture_names|
49
+ fixture_names = @loaded_fixture_sets[decorated_fixture_set_name].fixtures.keys if fixture_names.empty?
38
50
 
39
51
  instances = fixture_names.map do |fixture_name|
40
52
  fixture_set[fixture_name.to_s].find
@@ -1,3 +1,3 @@
1
1
  class FixtureBox
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeyu Web Inc.
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Dynamically creating fixtures.
41
+ description: Dynamically creating ActiveRecord Fixtures.
42
42
  email:
43
43
  - yuichi.takeuchi@takeyuweb.co.jp
44
44
  executables: []
@@ -74,5 +74,5 @@ rubyforge_project:
74
74
  rubygems_version: 2.7.3
75
75
  signing_key:
76
76
  specification_version: 4
77
- summary: Dynamically creating fixtures.
77
+ summary: Dynamically creating ActiveRecord Fixtures.
78
78
  test_files: []