Skip to content

Commit

Permalink
Fixed field group specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tillman committed Dec 6, 2011
1 parent 0f3bd27 commit 6507f7e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/models/fields/field_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ def core_fields
def custom_fields
fields.where(:type => 'CustomField')
end

def self.with_tags(tag_ids)
where 'tag_id IS NULL OR tag_id IN (?)', tag_ids
end
end

3 changes: 2 additions & 1 deletion lib/fat_free_crm/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def fields

module InstanceMethods
def field_groups
self.class.field_groups.where(['tag_id IS NULL OR tag_id IN (?)', tag_ids])
field_groups = self.class.field_groups
respond_to?(:tag_ids) ? field_groups.with_tags(tag_ids) : field_groups
end

def assign_attributes(new_attributes, options = {})
Expand Down
9 changes: 5 additions & 4 deletions spec/factories/field_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

Factory.sequence(:field_position) {|x| x }

Factory.sequence :field_name do |x|
(Faker::Internet.user_name + x.to_s).gsub(/[^a-z0-9_]/, '').gsub(/[_ ]+/, '_')
Factory.sequence :field_label do |x|
Faker::Internet.user_name + x.to_s
end


Factory.define :field_group do |f|
f.klass_name { Factory.next(:klass_name) }
f.label { Factory.next(:field_label) }
end


Factory.define :field do |f|
f.type "Field"
f.field_group { Factory.create(:field_group) }
f.position { Factory.next(:field_position) }
f.name { Factory.next(:field_name) }
f.label {|f| f.name }
f.label { Factory.next(:field_label) }
f.name { |f| f.label.downcase.gsub(/[^a-z0-9]+/, '_') }
f.as "string"
f.updated_at { Factory.next(:time) }
f.created_at { Factory.next(:time) }
Expand Down
15 changes: 0 additions & 15 deletions spec/helpers/admin/field_groups_helper_spec.rb

This file was deleted.

0 comments on commit 6507f7e

Please sign in to comment.