superdupe 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Dupe::Database::Record do
4
- describe "new" do
5
- it "should create an object that is a kind of Hash" do
6
- Dupe::Database::Record.new.should be_kind_of(Hash)
7
- end
8
- end
9
-
10
- describe "id" do
11
- it "should allow us to set the record id (and not the object id)" do
12
- d = Dupe::Database::Record.new
13
- d.id.should == nil
14
- d[:id].should == nil
15
- d.id = 1
16
- d.id.should == 1
17
- d[:id].should == 1
18
- end
19
- end
20
-
21
- describe "method_missing" do
22
- it "should allow us to access hash keys as if they were object attributes" do
23
- d = Dupe::Database::Record.new
24
- d[:some_key].should == nil
25
- d.some_key.should == nil
26
- d.some_key = 1
27
- d.some_key.should == 1
28
- d[:some_key].should == 1
29
- d[:another_key] = 2
30
- d.another_key.should == 2
31
- d[:another_key].should == 2
32
- end
33
- end
34
-
35
- describe "inspect" do
36
- it "should show the class name" do
37
- d = Dupe::Database::Record.new
38
- d.inspect.should match(/^<#Dupe::Database::Record/)
39
- end
40
-
41
- it "should show the key/value pairs as attributes" do
42
- d = Dupe::Database::Record.new
43
- d.title = 'test'
44
- d.inspect.should match(/title="test"/)
45
- d.author = Dupe::Database::Record.new
46
- d.inspect.should match(/author=<#Dupe::Database::Record/)
47
- end
48
-
49
- it "should show Fake::<model_name> when the record has a model" do
50
- b = Dupe.create :book
51
- b.inspect.should match(/^<#Duped::Book/)
52
- b.author = Dupe.create :author
53
- b.inspect.should match(/^<#Duped::Book/)
54
- b.inspect.should match(/author=<#Duped::Author/)
55
- end
56
- end
57
-
58
- describe "__model__" do
59
- it "should have a __model__ instance variable" do
60
- proc {Dupe::Database::Record.new.__model__}.should_not raise_error
61
- end
62
-
63
- it "should all you to set the __model_name__ instance variable" do
64
- r = Dupe::Database::Record.new
65
- proc {r.__model__ = :book}.should_not raise_error
66
- r.__model__.should == :book
67
- end
68
- end
69
-
70
- end
@@ -1,17 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Dupe::Network::RestValidation do
4
- before do
5
- class TestRestValidation
6
- include Dupe::Network::RestValidation
7
- end
8
- end
9
-
10
- describe "validate_request_type" do
11
- it "should raise an exception if the request type isn't :get, :post, :put, or :delete" do
12
- proc {
13
- TestRestValidation.new.validate_request_type(:unknown_request_type)
14
- }.should raise_error(Dupe::Network::UnknownRestVerbError)
15
- end
16
- end
17
- end
@@ -1,109 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Dupe::Model::Schema do
4
- describe "new" do
5
- it "should initialize attribute_templates to an empty hash" do
6
- Dupe::Model::Schema.new.attribute_templates.should == {}
7
- end
8
-
9
- it "should initialize after_create_callbacks to an empty array" do
10
- Dupe::Model::Schema.new.after_create_callbacks.should == []
11
- end
12
- end
13
-
14
- describe "dynamic attribute_template creation methods" do
15
- before do
16
- @schema = Dupe::Model::Schema.new
17
- end
18
-
19
- describe "called with no parameters" do
20
- it "should create a new attribute template with no transformer and no default value" do
21
- @schema.title
22
- @schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
23
- @schema.attribute_templates[:title].name.should == :title
24
- @schema.attribute_templates[:title].default.should be_nil
25
- @schema.attribute_templates[:title].transformer.should be_nil
26
- end
27
- end
28
-
29
- describe "called with a single parameter, but no block" do
30
- it "should create a new attribute template with a default value but no transformer" do
31
- @schema.title 'Untitled'
32
- @schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
33
- @schema.attribute_templates[:title].name.should == :title
34
- @schema.attribute_templates[:title].default.should == 'Untitled'
35
- @schema.attribute_templates[:title].transformer.should be_nil
36
- end
37
- end
38
-
39
- describe "called with a block that accepts a parameter" do
40
- it "should create a new attribute template without a default value, but with a tranformer" do
41
- @schema.title {|dont_care| 'test'}
42
- @schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
43
- @schema.attribute_templates[:title].name.should == :title
44
- @schema.attribute_templates[:title].default.should be_nil
45
- @schema.attribute_templates[:title].transformer.should be_kind_of(Proc)
46
- end
47
- end
48
-
49
- describe "called with a block that doesn't accept a parameter" do
50
- it "should create a new attribute template without a transformer, and with the block as the default value" do
51
- @schema.title { 'knock' * 3 }
52
- @schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
53
- @schema.attribute_templates[:title].name.should == :title
54
- @schema.attribute_templates[:title].default.should be_kind_of(Proc)
55
- @schema.attribute_templates[:title].default.call.should == "knockknockknock"
56
- @schema.attribute_templates[:title].transformer.should be_nil
57
- end
58
- end
59
-
60
- describe "called with a block and a parameter" do
61
- it "should create a new attribute template with a default value AND with a tranformer" do
62
- @schema.title('Untitled') {|dont_care| 'test'}
63
- @schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
64
- @schema.attribute_templates[:title].name.should == :title
65
- @schema.attribute_templates[:title].default.should == 'Untitled'
66
- @schema.attribute_templates[:title].transformer.should be_kind_of(Proc)
67
- end
68
- end
69
- end
70
-
71
- describe "#after_create" do
72
- before do
73
- @schema = Dupe::Model::Schema.new
74
- end
75
-
76
- it "should require a block that accepts a single parameter" do
77
- proc { @schema.after_create }.should raise_error(ArgumentError)
78
- proc { @schema.after_create { "parameterless block" } }.should raise_error(ArgumentError)
79
- proc { @schema.after_create {|s| s.title = 'test' } }.should_not raise_error
80
- end
81
-
82
- it "should add the callback to the list of after_create_callbacks" do
83
- @schema.after_create_callbacks.should be_empty
84
- @schema.after_create {|s| s.title = 'test'}
85
- @schema.after_create_callbacks.length.should == 1
86
- @schema.after_create_callbacks.first.should be_kind_of(Proc)
87
- end
88
-
89
- end
90
-
91
- describe "#uniquify" do
92
- before do
93
- @schema = Dupe::Model::Schema.new
94
- end
95
-
96
- it "should only accept a list of symbols" do
97
- proc { @schema.uniquify }.should raise_error(ArgumentError, "You must pass at least one attribute to uniquify.")
98
- proc { @schema.uniquify :hash => 'value' }.should raise_error(ArgumentError, "You may only pass symbols to uniquify.")
99
- proc { @schema.uniquify :one, :two}.should_not raise_error
100
- end
101
-
102
- it "should create after_create_callbacks for each symbol passed to it" do
103
- @schema.after_create_callbacks.should be_empty
104
- @schema.uniquify :title, :label
105
- @schema.after_create_callbacks.length.should == 2
106
- @schema.after_create_callbacks.first.should be_kind_of(Proc)
107
- end
108
- end
109
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Sequence do
4
- describe "new" do
5
- it "should intialize the current value to whatever is passed in (or 1 by default)" do
6
- Sequence.new.current_value.should == 1
7
- Sequence.new(500).current_value.should == 500
8
- end
9
-
10
- it "should accept a block that takes a single parameter" do
11
- proc {Sequence.new 1, proc {}}.should raise_error(ArgumentError, "Your block must accept a single parameter")
12
- proc {Sequence.new 1, proc {|n| n}}.should_not raise_error
13
- proc {Sequence.new 1, proc {|n,m| n}}.should raise_error(ArgumentError, "Your block must accept a single parameter")
14
- s = Sequence.new 1, proc {|n| "email-#{n}@address.com"}
15
- s.current_value.should == 1
16
- end
17
- end
18
-
19
- describe "next" do
20
- it "should return the next value in the sequence, then increment the current value" do
21
- s = Sequence.new
22
- s.next.should == 1
23
- s.current_value.should == 2
24
- s.next.should == 2
25
- s.current_value.should == 3
26
-
27
- s = Sequence.new(500)
28
- s.next.should == 500
29
- s.current_value.should == 501
30
- s.next.should == 501
31
- s.current_value.should == 502
32
-
33
- s = Sequence.new 1, proc {|n| "email-#{n}@address.com"}
34
- s.next.should == "email-1@address.com"
35
- s.next.should == "email-2@address.com"
36
- s.current_value.should == 3
37
- end
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe String do
4
- describe "plural?" do
5
- it "should report plural symbols as plural" do
6
- 'apples'.plural?.should == true
7
- 'apple'.plural?.should == false
8
- end
9
- end
10
-
11
- describe "singular?" do
12
- it "should report singular items as singular" do
13
- 'apples'.singular?.should == false
14
- 'apple'.singular?.should == true
15
- end
16
- end
17
-
18
- describe "indent" do
19
- it "should default the indentional level to 2 spaces" do
20
- 'apples'.indent.should == " apples"
21
- end
22
-
23
- it "should accept an indentional level" do
24
- 'apples'.indent(4).should == " apples"
25
- end
26
-
27
- it "should indent each line of the string" do
28
- "apples\noranges".indent(2).should == " apples\n oranges"
29
- end
30
- end
31
- end
@@ -1,17 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Symbol do
4
- describe "plural?" do
5
- it "should report plural symbols as plural" do
6
- :apples.plural?.should == true
7
- :apple.plural?.should == false
8
- end
9
- end
10
-
11
- describe "singular?" do
12
- it "should report singular items as singular" do
13
- :apples.singular?.should == false
14
- :apple.singular?.should == true
15
- end
16
- end
17
- end