Skip to content

Commit

Permalink
remove last_update_by_ip from items
Browse files Browse the repository at this point in the history
  • Loading branch information
blahed committed Nov 15, 2012
1 parent a6e2d1b commit 0beaceb
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 37 deletions.
1 change: 0 additions & 1 deletion app/controllers/accounts/generic_accounts_controller.rb
Expand Up @@ -77,7 +77,6 @@ def account_params
:comments,
:group_ids
).merge(
:last_updated_by_ip => request.remote_ip,
:current_user => current_user
)
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/accounts/web_accounts_controller.rb
Expand Up @@ -78,7 +78,6 @@ def account_params
:comments,
:group_ids
).merge(
:last_updated_by_ip => request.remote_ip,
:current_user => current_user
)
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/notes_controller.rb
Expand Up @@ -75,7 +75,6 @@ def note_params
:body,
:group_ids
).merge(
:last_updated_by_ip => request.remote_ip,
:current_user => current_user
)
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/software_licenses_controller.rb
Expand Up @@ -77,7 +77,6 @@ def software_license_params
:comments,
:group_ids
).merge(
:last_updated_by_ip => request.remote_ip,
:current_user => current_user
)
end
Expand Down
11 changes: 1 addition & 10 deletions app/models/base_item.rb
Expand Up @@ -6,15 +6,10 @@ class BaseItem
attr_accessor :current_user

field :title, :type => String
field :last_updated_by, :type => String
field :last_updated_by_ip, :type => String

has_and_belongs_to_many :groups, :inverse_of => nil

before_validation :set_updated_by

validates_presence_of :title, :last_updated_by, :last_updated_by_ip
validates_format_of :last_updated_by_ip, :with => /\A\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}\z/
validates_presence_of :title

validate :groups_are_allowed

Expand All @@ -36,8 +31,4 @@ def groups_are_allowed

errors.add(:base, "The following groups are invalid `#{invalid_groups.join(', ')}'") unless invalid_groups.empty?
end

def set_updated_by
self.last_updated_by = current_user.id if current_user
end
end
5 changes: 0 additions & 5 deletions test/factories/base_items.rb
Expand Up @@ -6,36 +6,31 @@
factory :base_item do
title
current_user { create(:user) }
last_updated_by_ip '127.0.0.1'
end

factory :generic_account do
title
username 'foo'
password 'sssh'
current_user { create(:user) }
last_updated_by_ip '127.0.0.1'
end

factory :web_account do
title
username 'foo'
password 'sssh'
current_user { create(:user) }
last_updated_by_ip '127.0.0.1'
end

factory :note do
title
body 'foo'
current_user { create(:user) }
last_updated_by_ip '127.0.0.1'
end

factory :software_license do
title
license_key 'foo'
current_user { create(:user) }
last_updated_by_ip '127.0.0.1'
end
end
18 changes: 0 additions & 18 deletions test/models/base_item_test.rb
Expand Up @@ -16,24 +16,6 @@
item.errors.has_key?(:title).must_equal true
end

it "wont be valid without last_updated_by" do
item = FactoryGirl.build(:base_item, :current_user => nil)
item.wont_be :valid?
item.errors.has_key?(:last_updated_by).must_equal true
end

it "wont be valid without a proper last_updated_by_ip" do
item = FactoryGirl.build(:base_item, :last_updated_by_ip => nil)
item.wont_be :valid?
item.errors.has_key?(:last_updated_by_ip).must_equal true

%w[blah 123.123.123 3333.234.234.234 34s.23b.33d.234].each do |ip|
item = FactoryGirl.build(:base_item, :last_updated_by_ip => ip)
item.wont_be :valid?
item.errors.has_key?(:last_updated_by_ip).must_equal true
end
end

it "wont be valid unless the user is a member of the requested groups" do
@item.groups << FactoryGirl.create_list(:group, 3)
@item.wont_be :valid?
Expand Down

0 comments on commit 0beaceb

Please sign in to comment.