active_hash 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveHash::Base, "enum" do
4
-
5
- before do
6
- ActiveYaml::Base.set_root_path File.expand_path(File.dirname(__FILE__) + "/../fixtures")
7
-
8
- class Borough < ActiveYaml::Base
9
- include ActiveHash::Enum
10
- fields :name, :county, :population
11
- enum_accessor :name
12
- end
13
-
14
- class Neighborhood < ActiveHash::Base
15
- include ActiveHash::Enum
16
- fields :name, :county
17
- enum_accessor :name, :county
18
-
19
- self.data = [
20
- {:name => "Queen Ann", :county => "King"}
21
- ]
22
- end
23
- end
24
-
25
- after do
26
- Object.send(:remove_const, :Borough)
27
- Object.send(:remove_const, :Neighborhood)
28
- end
29
-
30
- describe "#enum_accessor" do
31
- it "can use a custom method" do
32
- Borough::BROOKLYN.should == Borough.find_by_name("Brooklyn")
33
- end
34
-
35
- it "sets the field used for accessing records by constants" do
36
- Neighborhood::QUEEN_ANN_KING.should == Neighborhood.find_by_name("Queen Ann")
37
- end
38
-
39
- it "ensures that values stored in the field specified are unique" do
40
- lambda do
41
- Class.new(ActiveHash::Base) do
42
- include ActiveHash::Enum
43
- self.data = [
44
- {:name => 'Woodford Reserve'},
45
- {:name => 'Bulliet Bourbon'},
46
- {:name => 'Woodford Reserve'}
47
- ]
48
- enum_accessor :name
49
- end
50
- end.should raise_error(ActiveHash::Enum::DuplicateEnumAccessor)
51
- end
52
-
53
- it "removes non-word characters from values before setting constants" do
54
- Movie = Class.new(ActiveHash::Base) do
55
- include ActiveHash::Enum
56
- self.data = [
57
- {:name => 'Die Hard 2', :rating => '4.3'},
58
- {:name => 'The Informant!', :rating => '4.3'},
59
- {:name => 'In & Out', :rating => '4.3'}
60
- ]
61
- enum_accessor :name
62
- end
63
-
64
- Movie::DIE_HARD_2.name.should == 'Die Hard 2'
65
- Movie::THE_INFORMANT.name.should == 'The Informant!'
66
- Movie::IN_OUT.name.should == 'In & Out'
67
- end
68
- end
69
-
70
- context "ActiveHash with an enum_accessor set" do
71
- describe "#save" do
72
- it "resets the constant's value to the updated record" do
73
- Borough::BROOKLYN.population.should == 2556598
74
- brooklyn = Borough.find_by_name("Brooklyn")
75
- brooklyn.population = 2556600
76
- brooklyn.save.should be_true
77
- Borough::BROOKLYN.population.should == 2556600
78
- end
79
- end
80
-
81
- describe ".create" do
82
- it "creates constants for new records" do
83
- bronx = Borough.create!(:name => "Bronx")
84
- Borough::BRONX.should == bronx
85
- end
86
-
87
- it "doesn't create constants for records missing the enum accessor field" do
88
- Borough.create(:name => "").should be_true
89
- Borough.create(:population => 12).should be_true
90
- end
91
- end
92
-
93
- describe ".delete_all" do
94
- it "unsets all constants for deleted records" do
95
- Borough.const_defined?("STATEN_ISLAND").should be_true
96
- Borough.delete_all.should be_true
97
- Borough.const_defined?("STATEN_ISLAND").should be_false
98
- end
99
- end
100
- end
101
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if Object.const_defined?(:ActiveModel)
4
-
5
- require 'test/unit'
6
- require 'test/unit/assertions'
7
- require 'active_model/lint'
8
-
9
- describe ActiveModel::Lint do
10
- include Test::Unit::Assertions
11
- include ActiveModel::Lint::Tests
12
-
13
- before do
14
- class Category < ActiveHash::Base
15
- end
16
- end
17
-
18
- after do
19
- Object.send(:remove_const, :Category)
20
- end
21
-
22
- # to_s is to support ruby-1.9
23
- ActiveModel::Lint::Tests.public_instance_methods.map { |m| m.to_s }.grep(/^test/).each do |m|
24
- example m.gsub('_', ' ') do
25
- send m
26
- end
27
- end
28
-
29
- def model
30
- Category.new
31
- end
32
-
33
- end
34
-
35
- end
36
-
@@ -1,8 +0,0 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'active_hash'
7
-
8
- require 'util/ruby_version.rb'