Search Results

Search found 10 results on 1 pages for 'gmile'.

Page 1/1 | 1 

  • Where are the factory_girl records?

    - by gmile
    I'm trying to perform an integration test via Watir and RSpec. So, I created a test file within /integration and wrote a test, which adds a test user into a base via factory_girl. The problem is — I can't actually perform a login with my test user. The test I wrote looks as following: ... before(:each) @user = Factory(:user) @browser = FireWatir::Firefox.new end it "should login" @browser.text_field(:id, "username").set(@user.username) @browser.text_field(:id, "password").set(@user.password) @browser.button(:id, "get_in").click end ... As I'm starting the test and see a "performance" in browser, it always fires up a Username is not valid error. I've started an investigation, and did a small trick. First of all I've started to have doubts if the factory actually creates the user in DB. So after the immediate call to factory I've put some puts User.find stuff only to discover that the user is actually in DB. Ok, but as user still couldn't have logged in I've decided to see if he's present in DB with my own eyes. I've added a sleep right after a factory call, and went to see what's in the DB at the moment. I was crushed to see that the user is actually missing there! How come? Still, when I'm trying to output a user within the code, he is actually being fetched from somewhere. So where does the records, made by factory_girl within a runtime lie? Is it test or dev DB? I don't get it. I've 10 times checked if I'm running my Mongrel in test mode (does it matter? I think it does, as I'm trying to tun an integration test) and if my database.yml holds the correct connection specific data. I'm using an authlogic, if that can give any clue (no, putting activate_authlogic doesn't work here).

    Read the article

  • A simple factory_girl question

    - by gmile
    I have two factories (post_factory.rb, comment_factory.rb) in separate files. I'd like to create a bit complex factory, which will create a post with associated comments for me. I created a third file, called complex_factory.rb, and wrote the following code: Factory.define :post_with_comments, :parent => :post do |post| post.after_create { |p| Factory(:user_last_state, :post => p) } end But rake spec raises an error, stating that the file is unaware of post and comment factories. At the very next moment, I naïvely wrote requires at the top: require "post_factory.rb" require "comment_factory.rb" But that didn't gave any proper result. Maybe this requires actually looking the wrong direction? Or they pretty much don't matter (as registering factories for visibility might be more complex that I assume). Am I missing something? Any ideas?

    Read the article

  • Establishing persistent connection to a database in Java

    - by gmile
    I've ran through several examples over the web, and found that every single time I need something from the DB, I should write the following code: try { // Step 1: Load the JDBC driver. Class.forName("mysql_driver_name"); // Step 2: Establish the connection to the database. String url = "jdbc:string_to_mysql_server"; Connection conn = DriverManager.getConnection(url,"user1","password"); // fetch from the DB ... } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } It's very annoying to put up this code every time I want something from the DB, so the question is - is there a way to only once connect entirely all my app to the DB somehow at the very start point, avoiding copy-pasting mentioned code, and then be able to do everything I want with DB? I've quickly looked through NetBeans's Project menu, but didn't find any clue on how to configurate a persistent connection to a selected DB. If it's important, i'm writing a purely desktop app, i.e. using Java EE. Also, it's worth mentioning that I'm a kinda beginner in Java.

    Read the article

  • RSpec: Expectation on model's not working while testing controller

    - by gmile
    I'm trying to write a functional test. My test looks as following: describe PostsController do it "should create a Post" do Post.should_receive(:new).once post :create, { :post => { :caption => "ThePost", :category => "MyCategory" } } end end My PostsController (a part of it actually) looks as following: PostController < ActiveRecord::Base def create @post = Post.new(params[:post]) end end Running the test I'm always receiving a failure, which says that the Post class expected :new but never got it. Still, the actual post is created. I'm a newbie to RSpec. Am I missing something?

    Read the article

  • should_receive in RSpec

    - by gmile
    As far as I know, should_receive is applied only to mock objects. What I want is to check, if a certain Class (not object) received a certain message, like: User.should_receive(:all).once How do I do that?

    Read the article

  • Excess errors on model from somewhere

    - by gmile
    I have a User model, and use an acts_as_authentic (from authlogic) on it. My User model have 3 validations on username and looks as following: User < ActiveRecord::Base acts_as_authentic validates_presence_of :username validates_length_of :username, :within => 4..40 validates_uniqueness_of :username end I'm writing a test to see my validations in action. Somehow, I get 2 errors instead of one when validating a uniqueness of a name. To see excess error, I do the following test: describe User do before(:each) do @user = Factory.build(:user) end it "should have a username longer then 3 symbols" do @user2 = Factory(:user) @user.username = @user2.username @user.save puts @user.errors.inspect end end I got 2 errors on username: @errors={"username"=>["has already been taken", "has already been taken"]}. Somehow the validation passes two times. I think authlogic causes that, but I don't have a clue on how to avoid that. Another case of problem is when I set username to nil. Somehow I get four validation errors instead of three: @errors={"username"=>["is too short (minimum is 3 characters)", "should use only letters, numbers, spaces, and .-_@ please.", "can't be blank", "is too short (minimum is 4 characters)"]} I think authlogic is one that causes this strange behaviour. But I can't even imagine on how to solve that. Any ideas?

    Read the article

  • Customizing jTable

    - by gmile
    I need to customize my jTable. All I need, is to put a custom Swing object (like jButon, jPanel, etc.) into the table cell. Is it possible? I'm trying: jTable.getModel.setValueAt(jPanel1,0,0) and jTable.getModel.setValueAt(jPanel1.getUI(),0,0) But the result is only a some kind of string, representing the object... Any ideas?

    Read the article

  • Passing direct parameters to a Controller#method when testing via RSpec

    - by gmile
    Normally to pass parameters via in RSpec we do: params[:my_key] = my_value get :my_method Where my_method deals with what it received from params. But in my controller I have a method, which takes args directly i.e.: def my_method(*args) ... end How do I call the method with those args from within the test? I've tried get :my_method(args) but Ruby interpreter complains about syntax error.

    Read the article

  • Excluding a folder from autotesting

    - by gmile
    I've just installed a ZenTest to use autotest in my project. I use rspec and have an integration folder inside it. As I don't want all my integration tests run every single time I start autospec , so I'd like to somehow restrict autospec from running tests in that folder. How do I exclude a chosen folder inside a /spec from running by autotest?

    Read the article

  • RSpec: in-depth differences between before(:all) and before(:each)

    - by gmile
    Ok, so I've ran into a very strange issue, directly connected with before blocks. I'm doing a integration testing via Watir and RSpec. For a simple test to check if user can perform a login I'm creating a 'user' record in the db by means of factory_girl. So I put the following code: before(:each) do @user = Factory(:user) end if "should perform a login" do # do stuff end In do stuff I call a browser and see how the user tries to login. Unfortunately, somehow he cannot do that — "Username isn't valid". After some investigation I discovered that if I put the code for creating user in before(:all) block, everything magically works. How's that? What's the difference between :all and :each in this context? Also, If I put the code for creating user actually in the test body, it still doesn't work (i.e. user somehow isn't added to the DB or something).

    Read the article

1