Skip to content

Commit

Permalink
Adding setters for a Position block's height and width. Added tests f…
Browse files Browse the repository at this point in the history
…or the getters.
  • Loading branch information
bamnet committed May 5, 2011
1 parent cad74fb commit 822b61f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/models/position.rb
Expand Up @@ -11,6 +11,22 @@ class Position < ActiveRecord::Base
def width
right-left
end

# Enable the width to be set of a position.
# The right is adjusted relative to the left.
# A Concerto-1 style accessor, mainly used
# for importing templates.
def width=(size)
self.right = left + size
end

# Enabling the height to be set for a position.
# The bottom is adjusted relative to the top.
# A Concerto-1 style accessor, mainly used
# for importing templates.
def height=(size)
self.bottom = top + size
end

# Compute the height of the position block.
# Another Concerto-1 style attribute, figuring out
Expand Down
29 changes: 26 additions & 3 deletions test/unit/position_test.rb
@@ -1,8 +1,31 @@
require 'test_helper'

class PositionTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true

# Test the height and width getters
test "width reads correctly" do
p = positions(:one)
assert_equal p.width-p.right+p.left, 0
end

test "height reads correctly" do
p = positions(:one)
assert_equal p.height-p.bottom+p.top, 0
end

# Test the height and width setters
test "width sets correctly" do
p = Position.new(:left => 0.1)
p.width = 0.5
assert_equal p.right, 0.6
assert_equal p.width, 0.5
end

test "height sets correctly" do
p = Position.new(:top => 0.1)
p.height = 0.5
assert_equal p.bottom, 0.6
assert_equal p.height, 0.5
end

end

0 comments on commit 822b61f

Please sign in to comment.