Displaying 7 results from an estimated 7 matches for "valid_attributes".
2009 Feb 28
7
be_valid (validates_format_of ..., :on => :create)
Greetings,
How to write Example which will check if model''s variable''s
format is valid using :on => :create, like this:
class User < ActiveRecord::Base
...
validates_format_of :email, :with => /.../, :on => :create
...
Using following code is not right:
it "should ..." do
@user = users(:example_user)
@user.email =
2009 Jan 16
3
rspec model testing - test on user defined validation- How do I test that the create failed.
I''m new to rspec and looking for way to test a validation I added to a model.
The test checks to see that if field1 has a value then field2 must be nil
and vice versa.
-------------------------------
When I did the rspec_scaffold it generated one test which worked
before :each do
@valid_attributes = {
:field1 = "value for field1"
:field2 = "value for field2"
}
MyTest.create!(@valid_attributes)
end
it "should create a new instance given valid attributes" do
MyTest.create!(@valid_attributes)
end
---------------------------------
Before coding I mod...
2008 Nov 01
2
stuck on a validates_presence_of unless issue
...So I have
something like this:
validates_presence_of :street_address, :city, :state, :postal_code
unless :address_blank?
address_blank? checks whether all of the address fields are blank.
If I run a test like this, it works:
describe "given attributes" do
before(:each) do
@valid_attributes = {
:first_name => "Jonny",
:middle_name => "D",
:last_name => "Miller",
:street_address => "123 This Street",
:street_address2 => "Suite 200",
:city => "Baltimore",...
2007 Sep 04
16
Failure Messages in RSpec
Having used JUnit and Test::Unit, I''m quite used to having the ability to
insert a failure message, which helps when tests fail.
For instance, the example RSpec that is generated for a model class
specifies that the model class is valid. Assuming this were supposed to be
true, and it failed, I''ve now got to duplicate the code in the test in order
to find out why it
2012 Nov 12
7
RSpec: controller POST create
...c-rails (2.11.4)
rspec 2.11.1
I am new to rspec. I don''t quite understand tests for POST create part.
I have generated scaffold, and simultaneously it generated
controller_spec.rb as well.
it "assigns a newly created plan as @plan" do
post :create, {:plan => valid_attributes}, valid_session
assigns(:plan).should be_a(Plan)
assigns(:plan).should be_persisted
end
is the default POST create test. It raises a failure, if I changed the
validations of Plan
class Plan < ActiveRecord::Base
validates :give_take, :presence => true
v...
2012 Apr 05
5
rspec: identical tests fails when repeated
...re''s the relevant code:
context "POST create" do
context "with user logged in" do
before(:each) do
@user = mock_model(User, :admin? => false, :guest? => false)
controller.stub(:current_user) { @user } # aka login
@attributes = valid_attributes
end
# succeeds
it "should create a new Premise" do
lambda{
post(:create, {:premise => @attributes}, :format => :json)
}.should change(Premise, :count).by(1)
end
# fails with CanCan::AccessDenied
it "should create a...
2008 Mar 13
22
Specifing methods in a steps_for block
....classify.constantize.count
end
When "the user adds an invalid $type" do |type|
post "/#{type.pluralize}/create", type.to_sym => {}
end
When "the user adds a valid $type" do |type|
post "/#{type.pluralize}/create", type.to_sym => valid_attributes
end
Then "there should be $number more $type? in the system" do |
number, type|
type.classify.constantize.count.should == (@initial_item_count +
number.to_i)
end
Then "there should be an error message explaining what went wrong" do
response.should have...