couch_potato 1.4.0 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +12 -8
  4. data/CHANGES.md +4 -0
  5. data/Gemfile +1 -1
  6. data/README.md +396 -276
  7. data/Rakefile +9 -9
  8. data/couch_potato-rspec.gemspec +20 -0
  9. data/couch_potato.gemspec +15 -16
  10. data/{active_support_4_0 → gemfiles/active_support_4_0} +3 -3
  11. data/{active_support_3_2 → gemfiles/active_support_4_1} +3 -2
  12. data/gemfiles/active_support_4_2 +11 -0
  13. data/lib/couch_potato-rspec.rb +3 -0
  14. data/lib/couch_potato.rb +3 -1
  15. data/lib/couch_potato/database.rb +42 -39
  16. data/lib/couch_potato/persistence/magic_timestamps.rb +5 -5
  17. data/lib/couch_potato/persistence/properties.rb +8 -2
  18. data/lib/couch_potato/persistence/simple_property.rb +11 -9
  19. data/lib/couch_potato/persistence/type_caster.rb +1 -1
  20. data/lib/couch_potato/railtie.rb +2 -0
  21. data/lib/couch_potato/version.rb +2 -1
  22. data/lib/couch_potato/view/base_view_spec.rb +18 -8
  23. data/lib/couch_potato/view/view_query.rb +2 -3
  24. data/spec/attachments_spec.rb +3 -3
  25. data/spec/callbacks_spec.rb +193 -113
  26. data/spec/conflict_handling_spec.rb +4 -4
  27. data/spec/create_spec.rb +5 -5
  28. data/spec/default_property_spec.rb +6 -6
  29. data/spec/destroy_spec.rb +5 -5
  30. data/spec/property_spec.rb +71 -61
  31. data/spec/rails_spec.rb +3 -3
  32. data/spec/railtie_spec.rb +12 -13
  33. data/spec/spec_helper.rb +3 -3
  34. data/spec/unit/active_model_compliance_spec.rb +16 -16
  35. data/spec/unit/attributes_spec.rb +36 -34
  36. data/spec/unit/base_view_spec_spec.rb +82 -35
  37. data/spec/unit/callbacks_spec.rb +2 -2
  38. data/spec/unit/couch_potato_spec.rb +3 -3
  39. data/spec/unit/create_spec.rb +12 -12
  40. data/spec/unit/custom_views_spec.rb +1 -1
  41. data/spec/unit/database_spec.rb +95 -95
  42. data/spec/unit/date_spec.rb +3 -3
  43. data/spec/unit/deep_dirty_attributes_spec.rb +104 -104
  44. data/spec/unit/dirty_attributes_spec.rb +19 -19
  45. data/spec/unit/forbidden_attributes_protection_spec.rb +4 -4
  46. data/spec/unit/initialize_spec.rb +37 -19
  47. data/spec/unit/json_spec.rb +4 -4
  48. data/spec/unit/lists_spec.rb +8 -8
  49. data/spec/unit/model_view_spec_spec.rb +14 -14
  50. data/spec/unit/persistence_spec.rb +6 -6
  51. data/spec/unit/properties_view_spec_spec.rb +4 -4
  52. data/spec/unit/rspec_matchers_spec.rb +73 -73
  53. data/spec/unit/rspec_stub_db_spec.rb +43 -42
  54. data/spec/unit/string_spec.rb +1 -1
  55. data/spec/unit/time_spec.rb +2 -2
  56. data/spec/unit/validation_spec.rb +1 -1
  57. data/spec/unit/view_query_spec.rb +54 -59
  58. data/spec/update_spec.rb +5 -5
  59. data/spec/view_updates_spec.rb +4 -4
  60. data/spec/views_spec.rb +43 -43
  61. metadata +18 -22
  62. data/lib/couch_potato/rspec.rb +0 -2
  63. data/lib/couch_potato/rspec/matchers.rb +0 -56
  64. data/lib/couch_potato/rspec/matchers/json2.js +0 -482
  65. data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +0 -53
  66. data/lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb +0 -166
  67. data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +0 -61
  68. data/lib/couch_potato/rspec/matchers/reduce_to_matcher.rb +0 -48
  69. data/lib/couch_potato/rspec/stub_db.rb +0 -57
@@ -30,12 +30,12 @@ describe CouchPotato::Database, 'rails specific behavior' do
30
30
  context 'load a document' do
31
31
  it "should load models whose constants are currently uninitialized (like with rails in development mode)" do
32
32
  CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Uninitialized', '_id' => '1')
33
- CouchPotato.database.load('1').class.name.should == 'Autoloader::Uninitialized'
33
+ expect(CouchPotato.database.load('1').class.name).to eq('Autoloader::Uninitialized')
34
34
  end
35
35
 
36
36
  it "should load nested models" do
37
37
  CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Nested::Nested2', '_id' => '1')
38
- CouchPotato.database.load('1').class.name.should == 'Autoloader::Nested::Nested2'
38
+ expect(CouchPotato.database.load('1').class.name).to eq('Autoloader::Nested::Nested2')
39
39
  end
40
40
  end
41
41
 
@@ -43,7 +43,7 @@ describe CouchPotato::Database, 'rails specific behavior' do
43
43
  it "should load models from a view whose constants are currently uninitialized" do
44
44
  doc = {JSON.create_id => 'WithUnloadedEmbedded', '_id' => '1', 'embedded' => {JSON.create_id => 'WithUnloadedEmbedded::Uninitialized'}}
45
45
  CouchPotato.couchrest_database.save_doc(doc)
46
- CouchPotato.database.view(WithUnloadedEmbedded.all).first.embedded.class.name.should == 'WithUnloadedEmbedded::Uninitialized'
46
+ expect(CouchPotato.database.view(WithUnloadedEmbedded.all).first.embedded.class.name).to eq('WithUnloadedEmbedded::Uninitialized')
47
47
  end
48
48
  end
49
49
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'yaml'
3
- require 'spec/mocks'
4
3
 
5
4
  module Rails
6
5
  def self.env
@@ -13,11 +12,11 @@ module Rails
13
12
  end
14
13
 
15
14
  def self.root
16
- RSpec::Mocks::Mock.new :join => ''
15
+ RSpec::Mocks::Double.new join: ''
17
16
  end
18
17
 
19
18
  def self.logger
20
- RSpec::Mocks::Mock.new :warn => nil
19
+ RSpec::Mocks::Double.new warn: nil
21
20
  end
22
21
  end
23
22
 
@@ -35,16 +34,16 @@ describe "railtie" do
35
34
  end
36
35
 
37
36
  before(:each) do
38
- File.stub(exist?: true)
37
+ allow(File).to receive_messages(exist?: true)
39
38
  end
40
39
 
41
40
  context 'when the yml file does not exist' do
42
41
  before(:each) do
43
- File.stub(exist?: false)
42
+ allow(File).to receive_messages(exist?: false)
44
43
  end
45
44
 
46
45
  it 'does not configure the database' do
47
- CouchPotato::Config.should_not_receive(:database_name=)
46
+ expect(CouchPotato::Config).not_to receive(:database_name=)
48
47
 
49
48
  CouchPotato.rails_init
50
49
  end
@@ -52,9 +51,9 @@ describe "railtie" do
52
51
 
53
52
  context 'yaml file contains only database names' do
54
53
  it "should set the database name from the yaml file" do
55
- File.stub(:read => "test: test_db")
54
+ allow(File).to receive_messages(:read => "test: test_db")
56
55
 
57
- CouchPotato::Config.should_receive(:database_name=).with('test_db')
56
+ expect(CouchPotato::Config).to receive(:database_name=).with('test_db')
58
57
 
59
58
  CouchPotato.rails_init
60
59
  end
@@ -62,26 +61,26 @@ describe "railtie" do
62
61
 
63
62
  context 'yaml file contains more configuration' do
64
63
  before(:each) do
65
- File.stub(:read => "test: \n database: test_db\n default_language: :erlang")
64
+ allow(File).to receive_messages(:read => "test: \n database: test_db\n default_language: :erlang")
66
65
  end
67
66
 
68
67
  it "set the database name from the yaml file" do
69
- CouchPotato::Config.should_receive(:database_name=).with('test_db')
68
+ expect(CouchPotato::Config).to receive(:database_name=).with('test_db')
70
69
 
71
70
  CouchPotato.rails_init
72
71
  end
73
72
 
74
73
  it 'sets the default language from the yaml file' do
75
- CouchPotato::Config.should_receive(:default_language=).with(:erlang)
74
+ expect(CouchPotato::Config).to receive(:default_language=).with(:erlang)
76
75
 
77
76
  CouchPotato.rails_init
78
77
  end
79
78
  end
80
79
 
81
80
  it "should process the yml file with erb" do
82
- File.stub(:read => "test: \n database: <%= 'db' %>")
81
+ allow(File).to receive_messages(:read => "test: \n database: <%= 'db' %>")
83
82
 
84
- CouchPotato::Config.should_receive(:database_name=).with('db')
83
+ expect(CouchPotato::Config).to receive(:database_name=).with('db')
85
84
 
86
85
  CouchPotato.rails_init
87
86
  end
@@ -34,7 +34,7 @@ end
34
34
  class BigDecimalContainer
35
35
  include CouchPotato::Persistence
36
36
 
37
- property :number, :type => BigDecimal
37
+ property :number, type: BigDecimal
38
38
  end
39
39
 
40
40
  def recreate_db
@@ -53,11 +53,11 @@ RSpec::Matchers.define :eql_ignoring_indentation do |expected|
53
53
  strip_indentation(string) == strip_indentation(expected)
54
54
  end
55
55
 
56
- failure_message_for_should do |actual|
56
+ failure_message do |actual|
57
57
  "expected\n#{strip_indentation(actual).inspect} to == \n#{strip_indentation(expected).inspect} but wasn't."
58
58
  end
59
59
 
60
- failure_message_for_should_not do |actual|
60
+ failure_message_when_negated do |actual|
61
61
  "expected\n#{strip_indentation(actual).inspect} to not == \n#{strip_indentation(expected).inspect} but wasn."
62
62
  end
63
63
 
@@ -12,6 +12,10 @@ begin
12
12
  end
13
13
  end
14
14
 
15
+ def assert_equal(one, other)
16
+ expect(one).to equal(other)
17
+ end
18
+
15
19
  class ActiveComment
16
20
  include CouchPotato::Persistence
17
21
  property :name
@@ -26,31 +30,31 @@ begin
26
30
 
27
31
  describe '#to_partial_path' do
28
32
  it 'returns a path based on the class name' do
29
- @model.to_partial_path.should == 'active_comments/active_comment'
33
+ expect(@model.to_partial_path).to eq('active_comments/active_comment')
30
34
  end
31
35
  end
32
36
 
33
37
  describe "#persisted?" do
34
38
  it "should return false if it is a new document " do
35
- @model.should_not be_persisted
39
+ expect(@model).not_to be_persisted
36
40
  end
37
41
 
38
42
  it "should be true if it was saved" do
39
43
  @comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
40
44
  CouchPotato.database.save_document! @comment
41
- @comment.should be_persisted
45
+ expect(@comment).to be_persisted
42
46
  end
43
47
  end
44
48
 
45
49
  describe "#to_key" do
46
50
  it "should return nil if the document was not persisted" do
47
- @model.to_key.should be_nil
51
+ expect(@model.to_key).to be_nil
48
52
  end
49
53
 
50
54
  it "should return the id of the document if it was persisted" do
51
55
  @comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
52
56
  CouchPotato.database.save_document! @comment
53
- @comment.to_key.should == [@comment.id]
57
+ expect(@comment.to_key).to eq([@comment.id])
54
58
  end
55
59
  end
56
60
 
@@ -58,31 +62,31 @@ begin
58
62
  describe "#errors" do
59
63
  it "should return a single error as array" do
60
64
  @model.valid?
61
- @model.errors[:name].should be_kind_of(Array)
65
+ expect(@model.errors[:name]).to be_kind_of(Array)
62
66
  end
63
67
 
64
68
  it "should return multiple errors as array" do
65
69
  @model.valid?
66
- @model.errors[:email].size.should == 2
70
+ expect(@model.errors[:email].size).to eq(2)
67
71
  end
68
72
 
69
73
  it "should return no error as an empty array" do
70
- @model.errors[:name].should == []
74
+ expect(@model.errors[:name]).to eq([])
71
75
  end
72
76
 
73
77
  it "should be able to be Marshal.dump'ed" do
74
- lambda { Marshal.dump(@model.errors) }.should_not raise_error
78
+ expect { Marshal.dump(@model.errors) }.not_to raise_error
75
79
  end
76
80
  end
77
81
 
78
82
  describe "#destroyed" do
79
83
  it "should return destroyed if the object is deleted" do
80
84
  @model._deleted = true
81
- @model.should be_destroyed
85
+ expect(@model).to be_destroyed
82
86
  end
83
87
 
84
88
  it "should not return destroyed if it's not deleted" do
85
- @model.should_not be_destroyed
89
+ expect(@model).not_to be_destroyed
86
90
  end
87
91
  end
88
92
 
@@ -91,14 +95,10 @@ begin
91
95
  end
92
96
 
93
97
  def assert_kind_of(klass, object)
94
- object.should be_a(klass)
98
+ expect(object).to be_a(klass)
95
99
  end
96
100
  end
97
101
 
98
102
  rescue LoadError
99
103
  STDERR.puts "WARNING: active_model gem not installed. Not running ActiveModel specs."
100
104
  end
101
-
102
-
103
-
104
-
@@ -21,40 +21,42 @@ describe "attributes" do
21
21
  it "should assign the attributes" do
22
22
  plant = Plant.new
23
23
  plant.attributes = {:leaf_count => 1}
24
- plant.leaf_count.should == 1
24
+ expect(plant.leaf_count).to eq(1)
25
25
  end
26
26
 
27
27
  it "should assign the attributes via []=" do
28
28
  plant = Plant.new
29
29
  plant[:leaf_count] = 1
30
- plant.leaf_count.should == 1
30
+ expect(plant.leaf_count).to eq(1)
31
31
  end
32
32
  end
33
33
 
34
34
  context "attributes" do
35
35
  it "should return the attributes" do
36
36
  plant = Plant.new(:leaf_count => 1)
37
- plant.attributes.should == {'leaf_count' => 1, 'created_at' => nil, 'updated_at' => nil,
38
- 'typed_leaf_count' => nil, 'typed_leaf_size' => nil, 'branch' => nil}
37
+ expect(plant.attributes).to eq({'leaf_count' => 1, 'created_at' => nil, 'updated_at' => nil,
38
+ 'typed_leaf_count' => nil, 'typed_leaf_size' => nil, 'branch' => nil})
39
39
  end
40
40
 
41
41
  it "should return the attributes via [symbol]" do
42
42
  plant = Plant.new(:leaf_count => 1)
43
- plant.attributes[:leaf_count].should eql(plant[:leaf_count])
44
- plant.attributes[:leaf_count].should eql(1)
43
+ expect(plant.attributes[:leaf_count]).to eql(plant[:leaf_count])
44
+ expect(plant.attributes[:leaf_count]).to eql(1)
45
45
  end
46
46
 
47
47
  it "should return the attributes via [string]" do
48
- plant = Plant.new(:leaf_count => 1)
49
- plant.attributes["leaf_count"].should eql(plant[:leaf_count])
50
- plant.attributes["leaf_count"].should eql(1)
48
+ plant = Plant.new(leaf_count: 1)
49
+
50
+ expect(plant.attributes["leaf_count"]).to eql(plant[:leaf_count])
51
+ expect(plant.attributes["leaf_count"]).to eql(1)
51
52
  end
52
53
  end
53
54
 
54
55
  context "has_key?" do
55
- it "should respond to has_key?" do
56
- plant = Plant.new(:leaf_count => 1)
57
- plant.has_key?(:leaf_count).should be_true
56
+ it 'should respond to has_key?' do
57
+ plant = Plant.new(leaf_count: 1)
58
+
59
+ expect(plant.has_key?(:leaf_count)).to be_truthy
58
60
  end
59
61
  end
60
62
 
@@ -62,21 +64,21 @@ describe "attributes" do
62
64
  context "accessing ghost attributes" do
63
65
  it "should allow me to access attributes that are in the couchdb document but not defined as a property" do
64
66
  plant = Plant.json_create({JSON.create_id => "Plant", "color" => "red", "leaf_count" => 1})
65
- plant.color.should == 'red'
67
+ expect(plant.color).to eq('red')
66
68
  end
67
69
 
68
70
  it "should raise a no method error when trying to read attributes that are not in the document" do
69
71
  plant = Plant.json_create({JSON.create_id => "Plant", "leaf_count" => 1})
70
- lambda do
72
+ expect do
71
73
  plant.length
72
- end.should raise_error(NoMethodError)
74
+ end.to raise_error(NoMethodError)
73
75
  end
74
76
 
75
77
  it "should raise a no method error if the document hasn't been loaded from the database" do
76
78
  plant = Plant.new
77
- lambda do
79
+ expect do
78
80
  plant.length
79
- end.should raise_error(NoMethodError, /undefined method `length'/)
81
+ end.to raise_error(NoMethodError, /undefined method `length'/)
80
82
  end
81
83
  end
82
84
 
@@ -87,91 +89,91 @@ describe "attributes" do
87
89
 
88
90
  context 'nested objects' do
89
91
  it 'assigns the attributes of nested objects' do
90
- Plant.new(:branch => {:leafs => 3}).branch.leafs.should == 3
92
+ expect(Plant.new(:branch => {:leafs => 3}).branch.leafs).to eq(3)
91
93
  end
92
94
  end
93
95
 
94
96
  describe "fixnum" do
95
97
  it 'rounds a float to a fixnum' do
96
98
  @plant.typed_leaf_count = 4.5
97
- @plant.typed_leaf_count.should == 5
99
+ expect(@plant.typed_leaf_count).to eq(5)
98
100
  end
99
101
 
100
102
  it "converts a string into a fixnum" do
101
103
  @plant.typed_leaf_count = '4'
102
- @plant.typed_leaf_count.should == 4
104
+ expect(@plant.typed_leaf_count).to eq(4)
103
105
  end
104
106
 
105
107
  it "converts a string into a negative fixnum" do
106
108
  @plant.typed_leaf_count = '-4'
107
- @plant.typed_leaf_count.should == -4
109
+ expect(@plant.typed_leaf_count).to eq(-4)
108
110
  end
109
111
 
110
112
  it "leaves a fixnum as is" do
111
113
  @plant.typed_leaf_count = 4
112
- @plant.typed_leaf_count.should == 4
114
+ expect(@plant.typed_leaf_count).to eq(4)
113
115
  end
114
116
 
115
117
  it "leaves nil as is" do
116
118
  @plant.typed_leaf_count = nil
117
- @plant.typed_leaf_count.should be_nil
119
+ expect(@plant.typed_leaf_count).to be_nil
118
120
  end
119
121
 
120
122
  it "sets the attributes to zero if a string given" do
121
123
  @plant.typed_leaf_count = 'x'
122
- @plant.typed_leaf_count.should == 0
124
+ expect(@plant.typed_leaf_count).to eq(0)
123
125
  end
124
126
 
125
127
  it "parses numbers out of a string" do
126
128
  @plant.typed_leaf_count = 'x123'
127
- @plant.typed_leaf_count.should == 123
129
+ expect(@plant.typed_leaf_count).to eq(123)
128
130
  end
129
131
 
130
132
  it "set the attributes to nil if given a blank string" do
131
133
  @plant.typed_leaf_count = ''
132
- @plant.typed_leaf_count.should be_nil
134
+ expect(@plant.typed_leaf_count).to be_nil
133
135
  end
134
136
  end
135
137
 
136
138
  context "float" do
137
139
  it "should convert a number in a string with a decimal place" do
138
140
  @plant.typed_leaf_size = '0.5001'
139
- @plant.typed_leaf_size.should == 0.5001
141
+ expect(@plant.typed_leaf_size).to eq(0.5001)
140
142
  end
141
143
 
142
144
  it "should convert a number in a string without a decimal place" do
143
145
  @plant.typed_leaf_size = '5'
144
- @plant.typed_leaf_size.should == 5.0
146
+ expect(@plant.typed_leaf_size).to eq(5.0)
145
147
  end
146
148
 
147
149
  it "should convert a negative number in a string" do
148
150
  @plant.typed_leaf_size = '-5.0'
149
- @plant.typed_leaf_size.should == -5.0
151
+ expect(@plant.typed_leaf_size).to eq(-5.0)
150
152
  end
151
153
 
152
154
  it "should leave a float as it is" do
153
155
  @plant.typed_leaf_size = 0.5
154
- @plant.typed_leaf_size.should == 0.5
156
+ expect(@plant.typed_leaf_size).to eq(0.5)
155
157
  end
156
158
 
157
159
  it "should leave nil as is" do
158
160
  @plant.typed_leaf_size = nil
159
- @plant.typed_leaf_size.should be_nil
161
+ expect(@plant.typed_leaf_size).to be_nil
160
162
  end
161
163
 
162
164
  it "should set the attributes to zero if a string given" do
163
165
  @plant.typed_leaf_size = 'x'
164
- @plant.typed_leaf_size.should == 0
166
+ expect(@plant.typed_leaf_size).to eq(0)
165
167
  end
166
168
 
167
169
  it "should parse numbers out of a string" do
168
170
  @plant.typed_leaf_size = 'x00.123'
169
- @plant.typed_leaf_size.should == 0.123
171
+ expect(@plant.typed_leaf_size).to eq(0.123)
170
172
  end
171
173
 
172
174
  it "should set the attributes to nil if given a blank string" do
173
175
  @plant.typed_leaf_size = ''
174
- @plant.typed_leaf_size.should be_nil
176
+ expect(@plant.typed_leaf_size).to be_nil
175
177
  end
176
178
  end
177
179
  end
@@ -11,14 +11,14 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
11
11
  CouchPotato::Config.default_language = @default_language
12
12
  end
13
13
 
14
- it "raises an error when passing invalid view parameters" do
15
- lambda {
16
- CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {:start_key => '1'}
17
- }.should raise_error(ArgumentError, "invalid view parameter: start_key")
14
+ it 'raises an error when passing invalid view parameters' do
15
+ expect {
16
+ CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {start_key: '1'}
17
+ }.to raise_error(ArgumentError, "invalid view parameter: start_key")
18
18
  end
19
19
 
20
- it "does not raise an error when passing valid view parameters" do
21
- lambda {
20
+ it 'does not raise an error when passing valid view parameters' do
21
+ expect {
22
22
  CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {
23
23
  :key => 'keyvalue',
24
24
  :startkey => 'keyvalue',
@@ -33,95 +33,142 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
33
33
  :group_level => 1,
34
34
  :reduce => false,
35
35
  :include_docs => true,
36
- :inclusive_end => true
36
+ :inclusive_end => true,
37
+ :list_params => {}
37
38
  }
38
- }.should_not raise_error
39
+ }.not_to raise_error
39
40
  end
40
41
 
41
42
  it "removes stale when it's nil" do
42
43
  spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {:stale => nil}
43
- spec.view_parameters.should == {}
44
+ expect(spec.view_parameters).to eq({})
44
45
  end
45
46
 
46
47
  it "converts a range passed as key into startkey and endkey" do
47
48
  spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {:key => '1'..'2'}
48
- spec.view_parameters.should == {:startkey => '1', :endkey => '2'}
49
+ expect(spec.view_parameters).to eq({:startkey => '1', :endkey => '2'})
49
50
  end
50
51
 
51
52
  it "converts a plain value to a hash with a key" do
52
53
  spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, '2'
53
- spec.view_parameters.should == {:key => '2'}
54
+ expect(spec.view_parameters).to eq({:key => '2'})
55
+ end
56
+
57
+ it 'merges the list params' do
58
+ spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, key: '2', list_params: {:x => 'y'}
59
+ expect(spec.view_parameters).to eq({:key => '2', :x => 'y'})
54
60
  end
55
61
 
56
62
  it "generates the design document path by snake_casing the class name but keeping double colons" do
57
63
  spec = CouchPotato::View::BaseViewSpec.new 'Foo::BarBaz', '', {}, ''
58
- spec.design_document.should == 'foo::bar_baz'
64
+ expect(spec.design_document).to eq('foo::bar_baz')
59
65
  end
60
66
 
61
67
  it "generates the design document independent of the view name by default" do
62
68
  CouchPotato::Config.split_design_documents_per_view = false
63
69
  spec = CouchPotato::View::BaseViewSpec.new 'User', 'by_login_and_email', {}, ''
64
- spec.design_document.should == 'user'
70
+ expect(spec.design_document).to eq('user')
65
71
  end
66
72
 
67
73
  it "generates the design document per view if configured to" do
68
74
  CouchPotato::Config.split_design_documents_per_view = true
69
75
  spec = CouchPotato::View::BaseViewSpec.new 'User', 'by_login_and_email', {}, ''
70
- spec.design_document.should == 'user_view_by_login_and_email'
76
+ expect(spec.design_document).to eq('user_view_by_login_and_email')
77
+ end
78
+
79
+ it 'adds the view name digest to the design doc name' do
80
+ CouchPotato::Config.split_design_documents_per_view = true
81
+ spec = CouchPotato::View::RawViewSpec.new 'User', 'by_login_and_email',
82
+ {digest_view_name: true, map: 'function(doc) {}'}, ''
83
+
84
+ expect(spec.design_document).to eq('user_view_by_login_and_email-375c815fcb4f977f330a2edfadc7f74d')
71
85
  end
72
86
 
87
+ it 'builds the name digest by hashing the map and reduce function if there is one' do
88
+ CouchPotato::Config.split_design_documents_per_view = true
89
+ spec = CouchPotato::View::RawViewSpec.new 'User', 'by_login_and_email',
90
+ {digest_view_name: true, map: 'function(doc) {}', reduce: 'function(key, values) {}'}, ''
91
+
92
+ expect(spec.design_document).to eq('user_view_by_login_and_email-c9f83cec3dab954a8ca56330006f187e')
93
+ end
94
+
95
+
73
96
  it "generates the design document independent of the list name by default" do
74
97
  CouchPotato::Config.split_design_documents_per_view = false
75
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil, :to_s => 'User'), '', {:list => 'test_list'}, {}
76
- spec.design_document.should == 'user'
98
+ spec = CouchPotato::View::BaseViewSpec.new double(lists: nil, :to_s => 'User'), '', {list: 'test_list'}, {}
99
+ expect(spec.design_document).to eq('user')
77
100
  end
78
101
 
79
102
  it "generates the design document per view if configured to" do
80
103
  CouchPotato::Config.split_design_documents_per_view = true
81
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil, :to_s => 'User'), '', {:list => :test_list}, {}
82
- spec.design_document.should == 'user_list_test_list'
104
+ spec = CouchPotato::View::BaseViewSpec.new double(lists: nil, :to_s => 'User'), '', {list: :test_list}, {}
105
+ expect(spec.design_document).to eq('user_list_test_list')
83
106
  end
84
107
 
85
108
  it "extracts the list name from the options" do
86
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => :test_list}, {}
87
- spec.list_name.should == :test_list
109
+ spec = CouchPotato::View::BaseViewSpec.new double(lists: nil), 'all', {list: :test_list}, {}
110
+ expect(spec.list_name).to eq(:test_list)
88
111
  end
89
112
 
90
113
  it "extracts the list from the view parameters" do
91
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {}, {:list => :test_list}
92
- spec.list_name.should == :test_list
114
+ spec = CouchPotato::View::BaseViewSpec.new double(lists: nil), 'all', {}, {list: :test_list}
115
+ expect(spec.list_name).to eq(:test_list)
93
116
  end
94
117
 
95
118
  it "prefers the list name from the view parameters over the one from the options" do
96
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => 'my_list'}, {:list => :test_list}
97
- spec.list_name.should == :test_list
119
+ spec = CouchPotato::View::BaseViewSpec.new double(lists: nil), 'all', {list: 'my_list'}, list: :test_list
120
+ expect(spec.list_name).to eq(:test_list)
121
+ end
122
+
123
+ it 'returns the view name' do
124
+ spec = CouchPotato::View::BaseViewSpec.new Object, 'by_id', {}, {}
125
+ expect(spec.view_name).to eq('by_id')
126
+ end
127
+
128
+ it 'adds a digest to the view name based on the map function content when passing digest_view_name' do
129
+ # need to use RawViewSpec here so we can pass a map function
130
+ spec = CouchPotato::View::RawViewSpec.new Object, 'by_id',
131
+ {digest_view_name: true, map: 'function() {}'}, {}
132
+
133
+ expect(spec.view_name).to eq('by_id-4644e3a3ef266d4e6b513dc79bad5ab7')
134
+ end
135
+
136
+ it 'adds a digest to the view name if configure to' do
137
+ begin
138
+ CouchPotato::Config.digest_view_names = true
139
+ # need to use RawViewSpec here so we can pass a map function
140
+ spec = CouchPotato::View::RawViewSpec.new Object, 'by_id',
141
+ {map: 'function() {}'}, {}
142
+
143
+ expect(spec.view_name).to eq('by_id-4644e3a3ef266d4e6b513dc79bad5ab7')
144
+ ensure
145
+ CouchPotato::Config.digest_view_names = false
146
+ end
98
147
  end
99
148
 
100
149
  it "returns the list function" do
101
- klass = stub 'class'
102
- klass.stub(:lists).with('test_list').and_return('<list_code>')
103
- spec = CouchPotato::View::BaseViewSpec.new klass, 'all', {:list => 'test_list'}, {}
104
- spec.list_function.should == '<list_code>'
150
+ klass = double 'class'
151
+ allow(klass).to receive(:lists).with('test_list').and_return('<list_code>')
152
+ spec = CouchPotato::View::BaseViewSpec.new klass, 'all', {list: 'test_list'}, {}
153
+ expect(spec.list_function).to eq('<list_code>')
105
154
  end
106
155
 
107
156
  it 'reads the language from the couch potato config by default' do
108
157
  CouchPotato::Config.default_language = :ruby
109
158
  spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {}
110
- spec.language.should == :ruby
159
+ expect(spec.language).to eq(:ruby)
111
160
  end
112
161
 
113
162
  it 'sets the language to the given language' do
114
- spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {:language => :erlang}, {}
115
- spec.language.should == :erlang
163
+ spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {language: :erlang}, {}
164
+ expect(spec.language).to eq(:erlang)
116
165
  end
117
166
 
118
167
  it 'post-processes the results' do
119
- filter = lambda{ |results| results.map{|r| r.to_i} }
120
- spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {:results_filter => filter}, {}
168
+ filter = -> (results) { results.map(&:to_i) }
169
+ spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {results_filter: filter}, {}
121
170
 
122
171
  expect(spec.process_results(['1'])).to eql([1])
123
172
  end
124
173
  end
125
174
  end
126
-
127
-