Skip to content

Commit

Permalink
Fixes for 1.8.7 and jruby
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jun 4, 2011
1 parent d08c01c commit 983feb0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
script: "bundle exec rspec spec/"
rvm:
- 1.8.7
- 1.9.2
- jruby
15 changes: 0 additions & 15 deletions lib/virtus/class_methods.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
module Virtus
module ClassMethods
# Chains Class.new to be able to set attributes during initialization of
# an object.
#
# @param [Hash] attributes
# the attributes hash to be set
#
# @return [Object]
#
# @api private
def new(attributes = {})
model = super
model.attributes = attributes
model
end

# Defines an attribute on an object's class.
#
# Usage:
Expand Down
14 changes: 13 additions & 1 deletion lib/virtus/instance_methods.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
module Virtus
module InstanceMethods
# Chains Class.new to be able to set attributes during initialization of
# an object.
#
# @param [Hash] attributes
# the attributes hash to be set
#
# @return [Object]
#
# @api private
def initialize(attributes = {})
self.attributes = attributes
end

# Returns a value of the attribute with the given name
#
# @param [Symbol] name
Expand All @@ -13,7 +26,6 @@ def attribute_get(name)
__send__(name)
end


# Sets a value of the attribute with the given name
#
# @param [Symbol] name
Expand Down
16 changes: 8 additions & 8 deletions spec/integration/virtus/class_methods/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@
end

it "creates attribute writer" do
described_class.public_instance_methods.should include(:"name=")
described_class.public_instance_methods.should include('name=')
end

it "creates attribute reader" do
described_class.public_instance_methods.should include(:name)
described_class.public_instance_methods.should include('name')
end

it "creates attribute private reader when :accessor => :private" do
described_class.private_instance_methods.should include(:email)
described_class.private_instance_methods.should include('email')
end

it "creates attribute private writer when :accessor => :private" do
described_class.private_instance_methods.should include(:"email=")
described_class.private_instance_methods.should include('email=')
end

it "creates attribute protected reader when :accessor => :protected" do
described_class.protected_instance_methods.should include(:address)
described_class.protected_instance_methods.should include('address')
end

it "creates attribute protected writer when :accessor => :protected" do
described_class.protected_instance_methods.should include(:"address=")
described_class.protected_instance_methods.should include('address=')
end

it "creates attribute private reader when :reader => :private" do
described_class.private_instance_methods.should include(:age)
described_class.private_instance_methods.should include('age')
end

it "creates attribute protected writer when :writer => :protected" do
described_class.protected_instance_methods.should include(:"bday=")
described_class.protected_instance_methods.should include('bday=')
end
end
end
2 changes: 1 addition & 1 deletion spec/unit/virtus/attributes/date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

context 'with a time' do
it_should_behave_like "a correct date" do
let(:value) { Time.new(year, month, day) }
let(:value) { Time.local(year, month, day) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/virtus/attributes/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
end

context 'with a non-date value' do
let(:value) { 'non-date' }
let(:value) { '2999' }
it { should == value }
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/virtus/class_methods/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.new(attributes)
model
end

def initialize(a=nil)
def initialize(attributes = {})
super
@email = "john@domain.com"
end
end
Expand Down

0 comments on commit 983feb0

Please sign in to comment.