MarkMenard-activerecordless 0.1.1

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/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 1
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,20 @@
1
+ module ActiveRecordless
2
+ class Base < ActiveRecord::Base
3
+ @@columns ||= []
4
+ cattr_accessor :columns
5
+ class << self
6
+ def column (name, sql_type = nil, default = nil, null = true)
7
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
8
+ end
9
+ alias_method :property, :column
10
+ end # singleton methods
11
+
12
+ def errors
13
+ @errors ||= ActiveRecord::Errors.new(self)
14
+ end
15
+
16
+ def valid?
17
+ errors.size == 0
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/active_recordless/base'
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActiverecordlessTest < Test::Unit::TestCase
4
+ context "A TestModel" do
5
+ setup do
6
+ @model = TestModel.new
7
+ end
8
+
9
+ should "have two attributes" do
10
+ assert_equal @model.attributes.size, 2
11
+ end
12
+
13
+ context "that is valid" do
14
+ setup do
15
+ @model.email = 'mark@mjm.net'
16
+ @model.body = 'A body'
17
+ @model.valid?
18
+ end
19
+
20
+ should "have an email of 'mark@mjm.net'" do
21
+ assert_equal @model.email, 'mark@mjm.net'
22
+ end
23
+
24
+ should "have a body of 'A body'" do
25
+ assert_equal @model.body, 'A body'
26
+ end
27
+ end
28
+
29
+ context "with an invalid email and body" do
30
+ setup do
31
+ @model.email = 'invalid'
32
+ @model.body = nil
33
+ @model.valid?
34
+ end
35
+
36
+ should "not be valid" do
37
+ assert !@model.valid?
38
+ end
39
+
40
+ should "have errors" do
41
+ assert @model.errors.size > 0
42
+ end
43
+ end
44
+ end
45
+
46
+ context "A TestModel2 that extends TestModel" do
47
+ setup do
48
+ @model = TestModel2.new()
49
+ end
50
+
51
+ should "have three attributes" do
52
+ assert_equal @model.attributes.size, 3
53
+ end
54
+
55
+ should "have an email attribute" do
56
+ assert @model.attributes.keys.any? { |key| key == 'email' }
57
+ end
58
+
59
+ should "have a body attribute" do
60
+ assert @model.attributes.keys.any? { |key| key == 'body' }
61
+ end
62
+
63
+ should "have a name attribute" do
64
+ assert @model.attributes.keys.any? { |key| key == 'name' }
65
+ end
66
+
67
+ context "with an email, body and name" do
68
+ setup do
69
+ @model.email = 'mark@mjm.net'
70
+ @model.body = 'body'
71
+ @model.name = 'name'
72
+ @model.valid?
73
+ end
74
+
75
+ should "be valid" do
76
+ assert @model.valid?
77
+ end
78
+
79
+ should "have an email of 'mark@mjm.net'" do
80
+ assert_equal @model.email, 'mark@mjm.net'
81
+ end
82
+
83
+ should "have a body of 'body'" do
84
+ assert_equal @model.body, 'body'
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ class TestModel < ActiveRecordless::Base
91
+ property :email, :string
92
+ property :body, :text
93
+
94
+ validates_format_of :email, :with => /^$|^\S+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/ix
95
+ validates_presence_of :body
96
+ end
97
+
98
+ class TestModel2 < TestModel
99
+ property :name, :string
100
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'activerecord'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + "../lib/")
9
+ require 'activerecordless'
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MarkMenard-activerecordless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Menard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: mark@mjm.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - VERSION.yml
26
+ - lib/active_recordless
27
+ - lib/active_recordless/base.rb
28
+ - lib/activerecordless.rb
29
+ - test/activerecordless_test.rb
30
+ - test/test_helper.rb
31
+ has_rdoc: true
32
+ homepage: http://github.com/MarkMenard/activerecordless
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --inline-source
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.2.0
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: Support to ActiveRecord to support tabless models.
58
+ test_files: []
59
+