sudo_attributes 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/beerlington/sudo_attributes"
12
12
  gem.authors = ["Peter Brown"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "sqlite3-ruby"
14
15
  gem.add_dependency "rails", ">= 2.3.0"
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
@@ -18,11 +19,10 @@ rescue LoadError
18
19
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
20
  end
20
21
 
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
26
  end
27
27
 
28
28
  begin
@@ -38,9 +38,9 @@ rescue LoadError
38
38
  end
39
39
  end
40
40
 
41
- task :test => :check_dependencies
41
+ task :spec => :check_dependencies
42
42
 
43
- task :default => :test
43
+ task :default => :spec
44
44
 
45
45
  require 'rake/rdoctask'
46
46
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -53,6 +53,12 @@ module SudoAttributes
53
53
  instance
54
54
  end
55
55
 
56
+ def sudo_create!(attributes=nil)
57
+ instance = sudo_new(attributes)
58
+ instance.save!
59
+ instance
60
+ end
61
+
56
62
  def sudo_new(attributes=nil)
57
63
  new(attributes, false)
58
64
  end
data/spec/spec_helper.rb CHANGED
@@ -4,4 +4,45 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  require 'rubygems'
5
5
  require 'active_record'
6
6
  require 'sudo_attributes'
7
- require 'spec'
7
+ require 'spec'
8
+
9
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
10
+
11
+ ActiveRecord::Schema.define(:version => 1) do
12
+ create_table :cats, :force => true do |t|
13
+ t.string :name
14
+ t.string :color
15
+ t.integer :age
16
+ end
17
+ end
18
+
19
+ module SudoAttributesTest
20
+ ARGUMENTS = [
21
+ { :protected => :name},
22
+ { :accessible => [:color, :age] },
23
+ :name,
24
+ nil # No arguments passed in
25
+ ]
26
+
27
+ def self.build_cat_class(arguments)
28
+
29
+ # Remove the Cat class if it's already been defined in previous run
30
+ Object.class_eval { remove_const "Cat" if const_defined? "Cat" }
31
+
32
+ # Create a new Cat class and evaluate 'has_sudo_attributes :arguments
33
+ klass = Class.new(ActiveRecord::Base)
34
+ Object.const_set("Cat", klass)
35
+
36
+ if arguments.nil?
37
+ Cat.class_eval do
38
+ attr_protected :name
39
+ has_sudo_attributes
40
+ end
41
+ else
42
+ Cat.class_eval do
43
+ validates_presence_of :color
44
+ has_sudo_attributes arguments
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,42 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
4
-
5
- ActiveRecord::Schema.define(:version => 1) do
6
- create_table :cats, :force => true do |t|
7
- t.string :name
8
- t.string :color
9
- t.integer :age
10
- end
11
- end
12
-
13
- module SudoAttributesTest
14
- ARGUMENTS = [
15
- { :protected => :name},
16
- { :accessible => [:color, :age] },
17
- :name,
18
- nil # No arguments passed in
19
- ]
20
-
21
- def self.build_cat_class(arguments)
22
-
23
- # Remove the Cat class if it's already been defined in previous run
24
- Object.class_eval { remove_const "Cat" if const_defined? "Cat" }
25
-
26
- # Create a new Cat class and evaluate 'has_sudo_attributes :arguments
27
- klass = Class.new(ActiveRecord::Base)
28
- Object.const_set("Cat", klass)
29
-
30
- if arguments.nil?
31
- Cat.class_eval do
32
- attr_protected :name
33
- has_sudo_attributes
34
- end
35
- else
36
- Cat.class_eval { has_sudo_attributes arguments }
37
- end
38
- end
39
- end
40
3
 
41
4
  describe "Cat" do
42
5
 
@@ -131,4 +94,39 @@ describe "Cat" do
131
94
  end
132
95
  end
133
96
  end
134
- end
97
+ end
98
+
99
+ describe "A Cat" do
100
+
101
+ before(:each) do
102
+ SudoAttributesTest::build_cat_class(:name)
103
+ end
104
+
105
+ context "when initialized with invalid params using sudo_create!" do
106
+
107
+ it "should raise an ActiveRecord exception" do
108
+ begin
109
+ Cat.sudo_create! :name => "Smiles", :age => 12
110
+ true.should == false
111
+ rescue ActiveRecord::RecordInvalid
112
+ true.should == true
113
+ end
114
+ end
115
+ end
116
+
117
+ context "when initialized with valid params using sudo_create!" do
118
+ it "should not raise an ActiveRecord exception" do
119
+ begin
120
+ Cat.sudo_create! :name => "Smiles", :color => "gray", :age => 12
121
+ true.should == true
122
+ rescue ActiveRecord::RecordInvalid
123
+ true.should == false
124
+ end
125
+ end
126
+
127
+ it "should have a name" do
128
+ @cat = Cat.sudo_create! :name => "Smiles", :color => "gray", :age => 12
129
+ @cat.name.should == "Smiles"
130
+ end
131
+ end
132
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sudo_attributes}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Brown"]
12
- s.date = %q{2010-09-29}
12
+ s.date = %q{2010-10-07}
13
13
  s.description = %q{Adds 'sudo' methods to update protected ActiveRecord attributes with mass assignment}
14
14
  s.email = %q{github@lette.us}
15
15
  s.extra_rdoc_files = [
@@ -28,9 +28,7 @@ Gem::Specification.new do |s|
28
28
  "spec/spec.opts",
29
29
  "spec/spec_helper.rb",
30
30
  "spec/sudo_attributes_spec.rb",
31
- "sudo_attributes.gemspec",
32
- "test/helper.rb",
33
- "test/test_sudo_attributes.rb"
31
+ "sudo_attributes.gemspec"
34
32
  ]
35
33
  s.homepage = %q{http://github.com/beerlington/sudo_attributes}
36
34
  s.rdoc_options = ["--charset=UTF-8"]
@@ -39,9 +37,7 @@ Gem::Specification.new do |s|
39
37
  s.summary = %q{Override ActiveRecord protected attributes with mass assignment}
40
38
  s.test_files = [
41
39
  "spec/spec_helper.rb",
42
- "spec/sudo_attributes_spec.rb",
43
- "test/helper.rb",
44
- "test/test_sudo_attributes.rb"
40
+ "spec/sudo_attributes_spec.rb"
45
41
  ]
46
42
 
47
43
  if s.respond_to? :specification_version then
@@ -50,13 +46,16 @@ Gem::Specification.new do |s|
50
46
 
51
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
48
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
53
50
  s.add_runtime_dependency(%q<rails>, [">= 2.3.0"])
54
51
  else
55
52
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
56
54
  s.add_dependency(%q<rails>, [">= 2.3.0"])
57
55
  end
58
56
  else
59
57
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
60
59
  s.add_dependency(%q<rails>, [">= 2.3.0"])
61
60
  end
62
61
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sudo_attributes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Brown
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-29 00:00:00 -04:00
18
+ date: 2010-10-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,9 +35,23 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: rails
38
+ name: sqlite3-ruby
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rails
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
41
55
  none: false
42
56
  requirements:
43
57
  - - ">="
@@ -49,7 +63,7 @@ dependencies:
49
63
  - 0
50
64
  version: 2.3.0
51
65
  type: :runtime
52
- version_requirements: *id002
66
+ version_requirements: *id003
53
67
  description: Adds 'sudo' methods to update protected ActiveRecord attributes with mass assignment
54
68
  email: github@lette.us
55
69
  executables: []
@@ -72,8 +86,6 @@ files:
72
86
  - spec/spec_helper.rb
73
87
  - spec/sudo_attributes_spec.rb
74
88
  - sudo_attributes.gemspec
75
- - test/helper.rb
76
- - test/test_sudo_attributes.rb
77
89
  has_rdoc: true
78
90
  homepage: http://github.com/beerlington/sudo_attributes
79
91
  licenses: []
@@ -111,5 +123,3 @@ summary: Override ActiveRecord protected attributes with mass assignment
111
123
  test_files:
112
124
  - spec/spec_helper.rb
113
125
  - spec/sudo_attributes_spec.rb
114
- - test/helper.rb
115
- - test/test_sudo_attributes.rb
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'sudo_attributes'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSudoAttributes < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end