Skip to content

Commit

Permalink
Stubbed custom_field specs so that they don't mess with the database …
Browse files Browse the repository at this point in the history
…connection and break everything, like Factories
  • Loading branch information
ndbroadbent committed Nov 11, 2011
1 parent e045c89 commit 70e3e33
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions spec/models/custom_field_spec.rb
Expand Up @@ -24,8 +24,13 @@
describe CustomField do

it "should add a column to the database" do
c = Factory.create(:custom_field, :name => "cf_test_field", :klass_name => "Contact")
c.klass.columns.map(&:name).should include("cf_test_field")
CustomField.connection.should_receive(:add_column).
with("contacts", "cf_test_field", :string, {})

c = Factory.create(:custom_field,
:as => "string",
:name => "cf_test_field",
:klass_name => "Contact")
end

it "should generate a unique column name for a custom field" do
Expand Down Expand Up @@ -55,8 +60,8 @@
it "should return a safe list of types for the 'as' select options" do
{"email" => %w(string email url tel select radio),
"integer" => %w(integer float)}.each do |type, expected_arr|
c = Factory.create(:custom_field, :as => type)
opts = c.edit_as_options
c = Factory.build(:custom_field, :as => type)
opts = c.available_as
expected_arr.each {|t| opts.should include(t) }
end
end
Expand All @@ -67,15 +72,19 @@ def ar_column(custom_field, column)
end

it "should change a column's type for safe transitions" do
CustomField.connection.should_receive(:add_column).
with("contacts", "cf_test_field", :string, {})
CustomField.connection.should_receive(:change_column).
with("contacts", "cf_test_field", :text, {})

c = Factory.create(:custom_field,
:label => "Test Field",
:name => nil,
:as => "email",
:klass_name => "Contact")
ar_column(c, "cf_test_field").type.should == :string
c.as = "text"
c.save
ar_column(c, "cf_test_field").type.should == :text
end

end

0 comments on commit 70e3e33

Please sign in to comment.