basic_active_model 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem "rspec-rails", "~> 2.0.0.beta"
4
+ gem 'jeweler'
5
+ gem "rails", "~> 3.0"
6
+ gem "ruby-debug"
7
+
data/Gemfile.lock ADDED
@@ -0,0 +1,103 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
+ mail (~> 2.2.5)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4.1)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.12)
16
+ rack-test (~> 0.5.4)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4.1)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ activesupport (3.0.0)
31
+ arel (1.0.1)
32
+ activesupport (~> 3.0.0)
33
+ builder (2.1.2)
34
+ columnize (0.3.1)
35
+ diff-lcs (1.1.2)
36
+ erubis (2.6.6)
37
+ abstract (>= 1.0.0)
38
+ gemcutter (0.6.1)
39
+ git (1.2.5)
40
+ i18n (0.4.1)
41
+ jeweler (1.4.0)
42
+ gemcutter (>= 0.1.0)
43
+ git (>= 1.2.5)
44
+ rubyforge (>= 2.0.0)
45
+ json_pure (1.4.6)
46
+ linecache (0.43)
47
+ mail (2.2.6.1)
48
+ activesupport (>= 2.3.6)
49
+ mime-types
50
+ treetop (>= 1.4.5)
51
+ mime-types (1.16)
52
+ polyglot (0.3.1)
53
+ rack (1.2.1)
54
+ rack-mount (0.6.13)
55
+ rack (>= 1.0.0)
56
+ rack-test (0.5.6)
57
+ rack (>= 1.0)
58
+ rails (3.0.0)
59
+ actionmailer (= 3.0.0)
60
+ actionpack (= 3.0.0)
61
+ activerecord (= 3.0.0)
62
+ activeresource (= 3.0.0)
63
+ activesupport (= 3.0.0)
64
+ bundler (~> 1.0.0)
65
+ railties (= 3.0.0)
66
+ railties (3.0.0)
67
+ actionpack (= 3.0.0)
68
+ activesupport (= 3.0.0)
69
+ rake (>= 0.8.4)
70
+ thor (~> 0.14.0)
71
+ rake (0.8.7)
72
+ rspec (2.0.0.beta.22)
73
+ rspec-core (= 2.0.0.beta.22)
74
+ rspec-expectations (= 2.0.0.beta.22)
75
+ rspec-mocks (= 2.0.0.beta.22)
76
+ rspec-core (2.0.0.beta.22)
77
+ rspec-expectations (2.0.0.beta.22)
78
+ diff-lcs (>= 1.1.2)
79
+ rspec-mocks (2.0.0.beta.22)
80
+ rspec-core (= 2.0.0.beta.22)
81
+ rspec-expectations (= 2.0.0.beta.22)
82
+ rspec-rails (2.0.0.beta.22)
83
+ rspec (= 2.0.0.beta.22)
84
+ ruby-debug (0.10.3)
85
+ columnize (>= 0.1)
86
+ ruby-debug-base (~> 0.10.3.0)
87
+ ruby-debug-base (0.10.3)
88
+ linecache (>= 0.3)
89
+ rubyforge (2.0.4)
90
+ json_pure (>= 1.1.7)
91
+ thor (0.14.2)
92
+ treetop (1.4.8)
93
+ polyglot (>= 0.3.1)
94
+ tzinfo (0.3.23)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ jeweler
101
+ rails (~> 3.0)
102
+ rspec-rails (~> 2.0.0.beta)
103
+ ruby-debug
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Novagile, Written by Nicolas Blanco.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,42 @@
1
+ h1. BasicActiveModel
2
+
3
+ BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.
4
+ It does not provide any kind of implementation. It may be used to create static models (search, contact us, etc.).
5
+
6
+ It includes ActiveModel validations and may be initialized with an argument Hash with optional mass assignment security.
7
+
8
+ Please take a look of the specs for more information...
9
+
10
+ h2. Installation
11
+
12
+ In your Gemfile:
13
+
14
+ <pre>
15
+ gem "basic_active_model"
16
+ </pre>
17
+
18
+ h2. Example
19
+
20
+ <pre>
21
+ class ContactUs < BasicActiveModel
22
+ attr_accessor :email, :subject, :body, :admin
23
+ attr_accessible :email, :subject, :body
24
+ validates_presence_of :body
25
+ end
26
+
27
+ ...
28
+ (in the view)
29
+ ...
30
+ = form_for @contact_us do |f|
31
+ = f.text_field :email
32
+ ...
33
+
34
+ ...
35
+ (in the ContactUs controller)
36
+ ...
37
+
38
+ @contact_us = ContactUs.new(params[:contact_us])
39
+ if @contact_us.valid?
40
+ ...
41
+ </pre>
42
+
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require "rake"
2
+ require "rake/rdoctask"
3
+ require "rspec"
4
+ require "rspec/core/rake_task"
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "basic_active_model"
10
+ gem.summary = %Q{BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.}
11
+ gem.description = %Q{BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.}
12
+ gem.email = "slainer68@gmail.com"
13
+ gem.homepage = "http://github.com/novagile/basic_active_model"
14
+ gem.authors = ["slainer68"]
15
+ gem.add_development_dependency "rspec", ">= 2.0.0.beta.22"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ Rspec::Core::RakeTask.new(:spec) do |spec|
24
+ spec.pattern = "spec/**/*_spec.rb"
25
+ end
26
+
27
+ Rake::RDocTask.new do |rdoc|
28
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
29
+
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = "basic_active_model #{version}"
32
+ rdoc.rdoc_files.include('README*')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
35
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{basic_active_model}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["slainer68"]
12
+ s.date = %q{2010-09-28}
13
+ s.description = %q{BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.}
14
+ s.email = %q{slainer68@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.textile",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "basic_active_model.gemspec",
28
+ "init.rb",
29
+ "lib/basic_active_model.rb",
30
+ "spec/basic_active_model_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/novagile/basic_active_model}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.}
38
+ s.test_files = [
39
+ "spec/basic_active_model_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
54
+ end
55
+ end
56
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "basic_active_model"
2
+
@@ -0,0 +1,17 @@
1
+ class BasicActiveModel
2
+ extend ActiveModel::Naming
3
+ include ActiveModel::Validations
4
+ include ActiveModel::MassAssignmentSecurity
5
+ include ActiveModel::Conversion
6
+
7
+ def persisted?
8
+ false
9
+ end
10
+
11
+ def initialize(attributes = {})
12
+ if attributes.present?
13
+ sanitize_for_mass_assignment(attributes).each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ class ContactForm < BasicActiveModel
4
+ attr_accessor :email, :subject, :body, :admin
5
+ attr_accessible :email, :subject, :body
6
+ validates_presence_of :body
7
+ end
8
+
9
+ describe 'BasicActiveModel' do
10
+ it 'should initialize without arguments' do
11
+ lambda { ContactForm.new }.should_not raise_error
12
+ end
13
+
14
+ it 'should initialize with a hash containing symbols and strings keys and set attributes' do
15
+ contact_form = ContactForm.new(:email => "yeah@yeah.com", "subject" => "lol")
16
+ contact_form.email.should == "yeah@yeah.com"
17
+ contact_form.subject.should == "lol"
18
+ end
19
+
20
+ it 'should ignore invalid attributes in the hash' do
21
+ contact_form = ContactForm.new(:invalid => "oh noes", :body => "plop")
22
+ contact_form.body.should == "plop"
23
+ end
24
+
25
+ it 'should have mass assignment security' do
26
+ contact_form = ContactForm.new(:email => "yeah@yeah.com", :admin => true)
27
+ contact_form.admin.should be_nil
28
+ end
29
+
30
+ it "should validate" do
31
+ contact_form = ContactForm.new
32
+ contact_form.should_not be_valid
33
+ contact_form.body = "plop"
34
+ contact_form.should be_valid
35
+ end
36
+
37
+ it "should respond to some required methods in order to pass it in a form" do
38
+ contact_form = ContactForm.new
39
+ contact_form.should_not be_persisted
40
+ contact_form.to_key.should be_nil
41
+ contact_form.to_param.should be_nil
42
+ end
43
+ end
44
+
@@ -0,0 +1,11 @@
1
+ require 'ruby-debug'
2
+ require 'rspec'
3
+
4
+ require "active_model"
5
+
6
+ require File.dirname(__FILE__) + '/../lib/basic_active_model'
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basic_active_model
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - slainer68
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-28 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196431
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 22
36
+ version: 2.0.0.beta.22
37
+ type: :development
38
+ version_requirements: *id001
39
+ description: BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.
40
+ email: slainer68@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - LICENSE
47
+ - README.textile
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.textile
54
+ - Rakefile
55
+ - VERSION
56
+ - basic_active_model.gemspec
57
+ - init.rb
58
+ - lib/basic_active_model.rb
59
+ - spec/basic_active_model_spec.rb
60
+ - spec/spec_helper.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/novagile/basic_active_model
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: BasicActiveModel provides a minimal architecture for a model that may be used in Rails forms.
95
+ test_files:
96
+ - spec/basic_active_model_spec.rb
97
+ - spec/spec_helper.rb