basic_model 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.travis.yml +7 -0
- data/Gemfile +2 -0
- data/Rakefile +10 -0
- data/basic_model.gemspec +25 -0
- data/gemfiles/Gemfile.activemodel-3.0.x +8 -0
- data/gemfiles/Gemfile.activemodel-3.1.x +8 -0
- data/lib/basic_model/version.rb +3 -0
- data/lib/basic_model.rb +1 -2
- data/test/basic_model_test.rb +55 -0
- metadata +16 -7
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/basic_model.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'basic_model/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'basic_model'
|
7
|
+
s.version = BasicModel::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Pete Browne']
|
10
|
+
s.email = ['me@petebrowne.com']
|
11
|
+
s.homepage = 'http://github.com/petebrowne/basic_model'
|
12
|
+
s.summary = 'BasicModel is a tiny Module that complies with the ActiveModel API'
|
13
|
+
s.description = 'BasicModel is intended to be used in a tableless model in Rails >= 3.0. It complies with the ActiveModel API and includes valdiations, so it can be used in form helpers without a problem.'
|
14
|
+
|
15
|
+
s.rubyforge_project = 'basic_model'
|
16
|
+
|
17
|
+
s.add_dependency 'activemodel', '~> 3.0'
|
18
|
+
s.add_dependency 'activesupport', '~> 3.0'
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = %w(lib)
|
25
|
+
end
|
data/lib/basic_model.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
Bundler.require
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class Post
|
7
|
+
include BasicModel
|
8
|
+
attr_accessor :title, :body
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def not_allowed=(value)
|
13
|
+
raise 'Not Allowed!'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Comment
|
18
|
+
include BasicModel
|
19
|
+
include ActiveModel::MassAssignmentSecurity
|
20
|
+
attr_accessor :name, :comment, :spam
|
21
|
+
|
22
|
+
attr_accessible :name, :comment
|
23
|
+
end
|
24
|
+
|
25
|
+
class BasicModelTest < ActiveSupport::TestCase
|
26
|
+
include ActiveModel::Lint::Tests
|
27
|
+
|
28
|
+
def setup
|
29
|
+
@model = Post.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_initialize_with_attributes
|
33
|
+
@model = Post.new(:title => 'Title', :body => 'Body')
|
34
|
+
assert_equal 'Title', @model.title
|
35
|
+
assert_equal 'Body', @model.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_do_not_call_private_methods
|
39
|
+
assert_nothing_raised do
|
40
|
+
Post.new(:not_allowed => 'Oops')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_mass_security_assignment
|
45
|
+
@model = Comment.new(:name => 'Bob', :comment => 'Great post!', :spam => false)
|
46
|
+
assert_nil @model.spam
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialize_with_yield
|
50
|
+
@model = Post.new do |post|
|
51
|
+
post.title = 'Title'
|
52
|
+
end
|
53
|
+
assert_equal 'Title', @model.title
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pete Browne
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|
@@ -71,9 +71,18 @@ extensions: []
|
|
71
71
|
extra_rdoc_files: []
|
72
72
|
|
73
73
|
files:
|
74
|
-
-
|
74
|
+
- .gitignore
|
75
|
+
- .travis.yml
|
76
|
+
- Gemfile
|
75
77
|
- LICENSE
|
76
78
|
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- basic_model.gemspec
|
81
|
+
- gemfiles/Gemfile.activemodel-3.0.x
|
82
|
+
- gemfiles/Gemfile.activemodel-3.1.x
|
83
|
+
- lib/basic_model.rb
|
84
|
+
- lib/basic_model/version.rb
|
85
|
+
- test/basic_model_test.rb
|
77
86
|
homepage: http://github.com/petebrowne/basic_model
|
78
87
|
licenses: []
|
79
88
|
|
@@ -107,5 +116,5 @@ rubygems_version: 1.8.5
|
|
107
116
|
signing_key:
|
108
117
|
specification_version: 3
|
109
118
|
summary: BasicModel is a tiny Module that complies with the ActiveModel API
|
110
|
-
test_files:
|
111
|
-
|
119
|
+
test_files:
|
120
|
+
- test/basic_model_test.rb
|