paperclip_database 2.3.0 → 2.3.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
  SHA1:
3
- metadata.gz: cfe008fb0a854193ec05d861183921b701c39792
4
- data.tar.gz: 96c9078fbc881ffb26a84025a8cec507ada14bba
3
+ metadata.gz: e61f9497eb7f63600507677ed812ec06d73b91f3
4
+ data.tar.gz: f7d6a7b6078a95793d1c2f5ed28f72aed0b95930
5
5
  SHA512:
6
- metadata.gz: bf69777dec19e8c447b8be26339910658059643f535c864859b9b9c1426b682653e8a6e2c917a4bd982524c6947cf989d8e6ed0e938a02c6093bc9d5418ac656
7
- data.tar.gz: 52b37c509f81772b957e1b72cb727b6f2d531c85e63c22a13d61081b107647e7e7e7f3fb05c29a79322edf95a0cd9ae37342ec2cc5f798464dd4de50a9625a39
6
+ metadata.gz: 2b2763dd5d3b108329f2ab1b22c9ee364881ce27e7dfb2b0e0c30e3530569a2fbb2af2e31ce5511200a16701864a291193e80628a1c065ce2086d39fc7342e63
7
+ data.tar.gz: 79cbf57c646fc0e96e853625f9e3d7777b1f5a870000117c0b2424cb3e2a51b795e67be37eadbb4d266bd186de81c2897edcf286b3f787c4689503a14d08eb98
@@ -82,7 +82,7 @@ module Paperclip
82
82
  end
83
83
 
84
84
  def setup_paperclip_files_association
85
- @paperclip_files_association_name = 'paperclip_files'
85
+ @paperclip_files_association_name = @paperclip_file_model.name.demodulize.tableize
86
86
  @database_table = @paperclip_file_model.table_name
87
87
  #FIXME: This fails when using set_table_name "<myname>" in your model
88
88
  #FIXME: This should be fixed in ActiveRecord...
@@ -170,6 +170,10 @@ module Paperclip
170
170
  end
171
171
  alias_method :to_io, :to_file
172
172
 
173
+ def files
174
+ instance.send("#{@paperclip_files_association_name}")
175
+ end
176
+
173
177
  def file_for(style)
174
178
  db_result = instance.send("#{@paperclip_files_association_name}").send(:file_for, style.to_s)
175
179
  raise RuntimeError, "More than one result for #{style}" if db_result.size > 1
@@ -1,3 +1,3 @@
1
1
  module PaperclipDatabase
2
- VERSION = "2.3.0" unless defined? PaperclipDatabase::VERSION
2
+ VERSION = "2.3.1" unless defined? PaperclipDatabase::VERSION
3
3
  end
@@ -24,7 +24,7 @@ describe "PaperclipDatabase" do
24
24
  end
25
25
 
26
26
  it "has association name" do
27
- expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
27
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'user_avatar_paperclip_files'
28
28
  end
29
29
 
30
30
  it "has model constant" do
@@ -32,7 +32,7 @@ describe "PaperclipDatabase" do
32
32
  end
33
33
 
34
34
  it "has association" do
35
- expect(@model.methods.include?(:paperclip_files)).to be_truthy
35
+ expect(@model.methods.include?(:user_avatar_paperclip_files)).to be_truthy
36
36
  end
37
37
  end
38
38
  describe "Namespaced model" do
@@ -59,7 +59,7 @@ describe "PaperclipDatabase" do
59
59
  end
60
60
 
61
61
  it "has association name" do
62
- expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
62
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'user_avatar_paperclip_files'
63
63
  end
64
64
 
65
65
  it "has model constant" do
@@ -67,7 +67,7 @@ describe "PaperclipDatabase" do
67
67
  end
68
68
 
69
69
  it "has association" do
70
- expect(@model.methods.include?(:paperclip_files)).to be_truthy
70
+ expect(@model.methods.include?(:user_avatar_paperclip_files)).to be_truthy
71
71
  end
72
72
  end
73
73
  end
@@ -1,21 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  ##
4
- ## named subject 'association' is the SUT
4
+ ## named subject 'attachment' is the SUT
5
5
  # args can be
6
6
  # [:table_name] The table name
7
7
  #
8
8
  shared_examples_for "major version API compatible" do |args|
9
9
  table_name = args[:table_name]
10
10
  describe "Major version compatible with table name '#{table_name}'" do
11
+ subject{attachment}
11
12
  it "has table name '#{table_name}'" do
12
- expect(association.instance_variable_get(:@database_table)).to eq table_name
13
+ expect(subject.instance_variable_get(:@database_table)).to eq table_name
13
14
  end
15
+ ##Basic (common)
16
+ it { is_expected.to respond_to(:exists?).with(1).argument }
17
+ it { is_expected.to respond_to(:flush_writes).with(0).argument }
18
+ it { is_expected.to respond_to(:flush_deletes).with(0).argument }
19
+ it { is_expected.to respond_to(:copy_to_local_file).with(2).arguments }
20
+
21
+ ##Database specific
22
+ it { is_expected.to respond_to(:files).with(0).arguments }
23
+ it { is_expected.to respond_to(:database_path).with(1).argument }
24
+ it { is_expected.to respond_to(:to_file).with(1).argument }
25
+ it { is_expected.to respond_to(:to_io).with(1).argument }
26
+ it { is_expected.to respond_to(:file_for).with(1).argument }
27
+ it { is_expected.to respond_to(:file_contents).with(1).argument }
14
28
  end
15
29
  end
16
30
 
17
31
  ## named subject 'namespace' is the SUT
18
- shared_examples_for "model in namespace" do |args|
32
+ shared_examples_for "model" do |args|
19
33
  describe "with default options" do
20
34
  let!(:model_name){"#{namespace}User"}
21
35
  let!(:attachment_name){'avatar'}
@@ -43,43 +57,33 @@ shared_examples_for "model in namespace" do |args|
43
57
  end
44
58
 
45
59
  describe "PaperclipDatabase" do
46
- describe "backward compatibility" do
47
- before(:example) do
48
- @attachment_table_name = defined?(attachment_table_name) ? attachment_table_name : attachment_name.tableize
49
- extra_paperclip_options = defined?(attachment_table_name)? {:database_table => attachment_table_name.to_sym} : {}
60
+ before(:example) do
61
+ @attachment_table_name = defined?(attachment_table_name) ? attachment_table_name : attachment_name.tableize
62
+ extra_paperclip_options = defined?(attachment_table_name)? {:database_table => attachment_table_name.to_sym} : {}
50
63
 
51
- build_model model_name, (defined?(model_table_name)? model_table_name: nil), attachment_name.to_sym, extra_paperclip_options
52
- @model_table_name = model_name.constantize.table_name
53
- create_model_tables @model_table_name, @attachment_table_name, attachment_name
54
- @model = model_name.constantize.new
55
- file = File.open(fixture_file('5k.png'))
64
+ build_model model_name, (defined?(model_table_name)? model_table_name: nil), attachment_name.to_sym, extra_paperclip_options
65
+ @model_table_name = model_name.constantize.table_name
66
+ create_model_tables @model_table_name, @attachment_table_name, attachment_name
67
+ @model = model_name.constantize.new
68
+ file = File.open(fixture_file('5k.png'))
56
69
 
57
- @model.send(:"#{attachment_name}=",file)
58
- @model.save
59
- end
60
- subject(:association){@model.avatar}
61
- after(:example) do
62
- reset_activerecord
63
- reset_database @model_table_name, @attachment_table_name
64
- end
70
+ @model.send(:"#{attachment_name}=",file)
71
+ @model.save
72
+ end
73
+ subject(:attachment){@model.avatar}
74
+ after(:example) do
75
+ reset_activerecord
76
+ reset_database @model_table_name, @attachment_table_name
77
+ end
65
78
 
66
- describe "no namespace" do
67
- subject(:namespace){''}
68
- it_behaves_like "model in namespace"
69
- end
70
- describe "namespace '::'" do
71
- subject(:namespace){'::'}
72
- it_behaves_like "model in namespace"
73
- end
74
- describe "namespace 'Object::'" do
75
- subject(:namespace){'Object::'}
76
- it_behaves_like "model in namespace"
77
- end
78
- describe "namespace 'Namespace::'" do
79
- before(:context) { Object.const_set('Namespace', Module.new()) }
80
- after(:context) { Object.send(:remove_const, 'Namespace') }
81
- subject(:namespace){'Namespace::'}
82
- it_behaves_like "model in namespace"
83
- end
79
+ describe "model with no namespace" do
80
+ subject(:namespace){''}
81
+ it_behaves_like "model"
82
+ end
83
+ describe "model in namespace 'Namespace::'" do
84
+ before(:context) { Object.const_set('Namespace', Module.new()) }
85
+ after(:context) { Object.send(:remove_const, 'Namespace') }
86
+ subject(:namespace){'Namespace::'}
87
+ it_behaves_like "model"
84
88
  end
85
89
  end
@@ -21,7 +21,7 @@ describe "PaperclipDatabase" do
21
21
  end
22
22
 
23
23
  it "has correct association name" do
24
- expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
24
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'namespace_model_avatar_paperclip_files'
25
25
  end
26
26
 
27
27
  it "has correct model constant" do
@@ -33,7 +33,7 @@ describe "PaperclipDatabase" do
33
33
  end
34
34
 
35
35
  it "has association" do
36
- expect(@model.methods.include?(:paperclip_files)).to be_truthy
36
+ expect(@model.methods.include?(:namespace_model_avatar_paperclip_files)).to be_truthy
37
37
  end
38
38
  end
39
39
  end
@@ -21,7 +21,7 @@ describe "PaperclipDatabase" do
21
21
  end
22
22
 
23
23
  it "has correct association name" do
24
- expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
24
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'user_avatar_paperclip_files'
25
25
  end
26
26
 
27
27
  it "has correct model constant" do
@@ -33,7 +33,7 @@ describe "PaperclipDatabase" do
33
33
  end
34
34
 
35
35
  it "has association" do
36
- expect(@model.methods.include?(:paperclip_files)).to be_truthy
36
+ expect(@model.methods.include?(:user_avatar_paperclip_files)).to be_truthy
37
37
  end
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarl Friis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip