snepo-dm-machinist 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/dm-machinist/machinist.rb +6 -1
- data/lib/dm-machinist.rb +24 -0
- data/spec/data/comment.rb +1 -0
- data/spec/dm_machinist_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -4
- metadata +1 -2
- data/spec/helpers.rb +0 -46
data/Rakefile
CHANGED
@@ -15,16 +15,21 @@ module DataMapper
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module DataMapperExtentions
|
18
|
+
|
18
19
|
def blueprint(&blueprint)
|
19
20
|
@blueprint = blueprint
|
20
21
|
end
|
21
22
|
|
22
23
|
def make(attributes = {})
|
24
|
+
@saved = false
|
25
|
+
@reloaded = false
|
23
26
|
raise "No blueprint for class #{self}" if @blueprint.nil?
|
24
27
|
lathe = Lathe.new(self, attributes)
|
25
28
|
lathe.instance_eval(&@blueprint)
|
26
29
|
unless Machinist.nerfed?
|
27
|
-
lathe.object.save
|
30
|
+
unless lathe.object.save
|
31
|
+
raise "Error: #{lath.object.errors.inspect}"
|
32
|
+
end
|
28
33
|
lathe.object.reload
|
29
34
|
end
|
30
35
|
returning(lathe.object) do |object|
|
data/lib/dm-machinist.rb
CHANGED
@@ -19,6 +19,30 @@ class Object
|
|
19
19
|
value
|
20
20
|
end
|
21
21
|
end
|
22
|
+
class String
|
23
|
+
# Ripped from Rails Inflectors
|
24
|
+
def camelize(first_letter_in_uppercase = true)
|
25
|
+
lower_case_and_underscored_word = self
|
26
|
+
if first_letter_in_uppercase
|
27
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
28
|
+
else
|
29
|
+
lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Ripped from Rails Inflectors
|
34
|
+
def constantize
|
35
|
+
camel_cased_word = self
|
36
|
+
names = camel_cased_word.split('::')
|
37
|
+
names.shift if names.empty? || names.first.empty?
|
38
|
+
|
39
|
+
constant = Object
|
40
|
+
names.each do |name|
|
41
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
42
|
+
end
|
43
|
+
constant
|
44
|
+
end
|
45
|
+
end
|
22
46
|
|
23
47
|
# Include the plugin in Resource
|
24
48
|
module DataMapper
|
data/spec/data/comment.rb
CHANGED
data/spec/dm_machinist_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe "Machinist" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def negative_failure_message
|
32
|
-
"expected the object not to be saved but
|
32
|
+
"expected the object not to be saved but it is"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe "Machinist" do
|
|
40
40
|
# class BeReloaded
|
41
41
|
# def matches?(target)
|
42
42
|
# @target = target
|
43
|
-
#
|
43
|
+
# TODO: Work out how to assert this...
|
44
44
|
# end
|
45
45
|
#
|
46
46
|
# def failure_message
|
@@ -127,7 +127,7 @@ describe "Machinist" do
|
|
127
127
|
|
128
128
|
it "should not nerf make within a block passed to make_unsaved" do
|
129
129
|
comment = nil
|
130
|
-
post = Post.make_unsaved do |post|
|
130
|
+
post = Post.make_unsaved(:title => "foo") do |post|
|
131
131
|
comment = Comment.make(:post => post)
|
132
132
|
end
|
133
133
|
post.should_not be_saved
|
data/spec/spec_helper.rb
CHANGED
@@ -5,10 +5,6 @@ require 'pathname'
|
|
5
5
|
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-machinist'
|
6
6
|
require Pathname(__FILE__).dirname.expand_path / 'helpers'
|
7
7
|
|
8
|
-
Spec::Runner.configure do |config|
|
9
|
-
config.include(CustomMatchers)
|
10
|
-
end
|
11
|
-
|
12
8
|
|
13
9
|
def load_driver(name, default_uri)
|
14
10
|
return false if ENV['ADAPTER'] != name.to_s
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snepo-dm-machinist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Barrie
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- spec/data/comment.rb
|
39
39
|
- spec/data/post.rb
|
40
40
|
- spec/dm_machinist_spec.rb
|
41
|
-
- spec/helpers.rb
|
42
41
|
- spec/sham_spec.rb
|
43
42
|
- spec/spec_helper.rb
|
44
43
|
- spec/spec.opts
|
data/spec/helpers.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
# Ripped from Rails Inflectors
|
3
|
-
def camelize(first_letter_in_uppercase = true)
|
4
|
-
lower_case_and_underscored_word = self
|
5
|
-
if first_letter_in_uppercase
|
6
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
7
|
-
else
|
8
|
-
lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Ripped from Rails Inflectors
|
13
|
-
def constantize
|
14
|
-
camel_cased_word = self
|
15
|
-
names = camel_cased_word.split('::')
|
16
|
-
names.shift if names.empty? || names.first.empty?
|
17
|
-
|
18
|
-
constant = Object
|
19
|
-
names.each do |name|
|
20
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
21
|
-
end
|
22
|
-
constant
|
23
|
-
end
|
24
|
-
end
|
25
|
-
module CustomMatchers
|
26
|
-
class DataMapperBeSaved
|
27
|
-
def initialize(expected)
|
28
|
-
@expected = expected
|
29
|
-
end
|
30
|
-
|
31
|
-
def matches?(target)
|
32
|
-
@target = target
|
33
|
-
p @target
|
34
|
-
p @expected
|
35
|
-
#satisfy expectation here
|
36
|
-
end
|
37
|
-
|
38
|
-
def failure_message
|
39
|
-
"expected #{@expected} but got #{@target}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def negative_failure_message
|
43
|
-
"expected #{@expected} to not be #{@target}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|