url_keyed_object 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
|
|
1
|
+
module UrlKeyedObject
|
2
|
+
module RSpec
|
3
|
+
module Matchers
|
4
|
+
def have_url_key
|
5
|
+
UrlKeyedObjectMatcher.new
|
6
|
+
end
|
7
|
+
|
8
|
+
class UrlKeyedObjectMatcher
|
9
|
+
def matches?(subject)
|
10
|
+
@subject = subject
|
11
|
+
@subject.class.respond_to?(:url_key_helper) && @subject.respond_to?(:generate_valid_url_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def description
|
15
|
+
"have declared has_url_key"
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message
|
19
|
+
"expected #{@subject.class.name} to have declared has_url_key"
|
20
|
+
end
|
21
|
+
|
22
|
+
def negative_failure_message
|
23
|
+
"expected #{@subject.class.name} to have NOT declared has_url_key"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_model/callbacks'
|
2
|
+
require 'active_model/mass_assignment_security'
|
3
|
+
|
4
|
+
class UrlKeyableModel
|
5
|
+
extend ActiveModel::Callbacks
|
6
|
+
include ActiveModel::MassAssignmentSecurity
|
7
|
+
|
8
|
+
define_model_callbacks :create
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@attributes = sanitize_for_mass_assignment(attrs)
|
12
|
+
end
|
13
|
+
|
14
|
+
def url_key
|
15
|
+
@attributes[:url_key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def read_attribute(key)
|
19
|
+
@attributes[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_attribute(key, value)
|
23
|
+
@attributes[key] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def save
|
27
|
+
run_callbacks :create do
|
28
|
+
#logic
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,41 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_model/callbacks'
|
3
|
-
require 'active_model/mass_assignment_security'
|
4
2
|
|
5
3
|
require 'url_keyed_object/active_record'
|
4
|
+
require 'fixtures/url_keyable_model'
|
6
5
|
|
7
|
-
|
8
|
-
class UrlKeyedModel
|
9
|
-
extend ActiveModel::Callbacks
|
10
|
-
include ActiveModel::MassAssignmentSecurity
|
11
|
-
|
12
|
-
define_model_callbacks :create
|
13
|
-
|
14
|
-
def initialize(attrs = {})
|
15
|
-
@attributes = sanitize_for_mass_assignment(attrs)
|
16
|
-
end
|
17
|
-
|
18
|
-
def url_key
|
19
|
-
@attributes[:url_key]
|
20
|
-
end
|
21
|
-
|
22
|
-
def read_attribute(key)
|
23
|
-
@attributes[key]
|
24
|
-
end
|
25
|
-
|
26
|
-
def write_attribute(key, value)
|
27
|
-
@attributes[key] = value
|
28
|
-
end
|
29
|
-
|
6
|
+
class UrlKeyedModel < UrlKeyableModel
|
30
7
|
extend UrlKeyedObject::ActiveRecord
|
31
8
|
|
32
9
|
has_url_key
|
33
|
-
|
34
|
-
def save
|
35
|
-
run_callbacks :create do
|
36
|
-
#logic
|
37
|
-
end
|
38
|
-
end
|
39
10
|
end
|
40
11
|
|
41
12
|
describe UrlKeyedObject::ActiveRecord do
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'fixtures/url_keyable_model'
|
4
|
+
require 'url_keyed_object/active_record'
|
5
|
+
require 'url_keyed_object/rspec/matchers'
|
6
|
+
|
7
|
+
describe "Verifying that a model object has been set up with has_url_key" do
|
8
|
+
include UrlKeyedObject::RSpec::Matchers
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@klass = Class.new(UrlKeyableModel)
|
12
|
+
@klass.extend UrlKeyedObject::ActiveRecord
|
13
|
+
end
|
14
|
+
|
15
|
+
it "provides a matcher which verifies positively" do
|
16
|
+
@klass.has_url_key
|
17
|
+
|
18
|
+
@klass.new.should have_url_key
|
19
|
+
end
|
20
|
+
|
21
|
+
it "provides a matcher which verifies negatively" do
|
22
|
+
@klass.new.should_not have_url_key
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_keyed_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2010-06-11 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70356035842620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.8'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70356035842620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mocha
|
27
|
-
requirement: &
|
27
|
+
requirement: &70356035842240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70356035842240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70356035841700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.5'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70356035841700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activerecord
|
49
|
-
requirement: &
|
49
|
+
requirement: &70356035841200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.2'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70356035841200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3
|
60
|
-
requirement: &
|
60
|
+
requirement: &70356035840820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70356035840820
|
69
69
|
description: Making it easy to work with Rails objects which use a URL key in their
|
70
70
|
URL instead of their database ID.
|
71
71
|
email: matt@reprocessed.org
|
@@ -81,10 +81,13 @@ files:
|
|
81
81
|
- cucumber.yml
|
82
82
|
- lib/url_keyed_object/active_record.rb
|
83
83
|
- lib/url_keyed_object/railtie.rb
|
84
|
+
- lib/url_keyed_object/rspec/matchers.rb
|
84
85
|
- lib/url_keyed_object.rb
|
85
86
|
- rails/init.rb
|
87
|
+
- spec/fixtures/url_keyable_model.rb
|
86
88
|
- spec/spec_helper.rb
|
87
89
|
- spec/url_keyed_object/active_record_spec.rb
|
90
|
+
- spec/url_keyed_object/rspec/matchers_spec.rb
|
88
91
|
- spec/url_keyed_object_spec.rb
|
89
92
|
- features/step_definitions/database_steps.rb
|
90
93
|
- features/step_definitions/eval_steps.rb
|
@@ -116,13 +119,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
119
|
version: '0'
|
117
120
|
requirements: []
|
118
121
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.8.
|
122
|
+
rubygems_version: 1.8.15
|
120
123
|
signing_key:
|
121
124
|
specification_version: 3
|
122
125
|
summary: Making it easy to work with objects with URL keys
|
123
126
|
test_files:
|
127
|
+
- spec/fixtures/url_keyable_model.rb
|
124
128
|
- spec/spec_helper.rb
|
125
129
|
- spec/url_keyed_object/active_record_spec.rb
|
130
|
+
- spec/url_keyed_object/rspec/matchers_spec.rb
|
126
131
|
- spec/url_keyed_object_spec.rb
|
127
132
|
- features/step_definitions/database_steps.rb
|
128
133
|
- features/step_definitions/eval_steps.rb
|