0

애플리케이션을 실행할 때 데이터베이스에 자동으로 테스트 데이터를 저장하고 싶습니다. 다음레일에서 테스트 데이터를 데이터베이스에 저장하십시오.

내가 사용하고자하는 데이터입니다 :

INSERT INTO `crm_donation_email_types` (`id`, `emailtype`, `created_at`, `updated_at`) VALUES 
(1, 'to', '2013-08-28 05:19:08', '2013-08-28 05:19:08'), 
(2, 'cc', '2013-08-28 05:19:15', '2013-08-28 05:19:15'), 
(3, 'bcc', '2013-08-28 05:19:26', '2013-08-28 05:19:26'), 
(4, 'from', '2013-08-28 05:19:35', '2013-08-28 05:19:35'); 

나는 곳이 줄을 추가하는 방법 알고 싶어를? 어느 하나도 실행하고 싶지 않아 rake db:migration/seed 하지만 데이터베이스에 포함되어야하는 서버를 시작하는 것처럼 내 응용 프로그램을 시작하고 싶습니다. 어떤 아이디어?

+0

config/initializers 폴더에 데이터를 채우는 파일을 만듭니다 –

+0

저에게 말할 수있는 코드는 제가 그 파일에 작성해야한다는 것입니다 ... 제가 새로운 것이며 그 파일에 코드를 사용하지 않았습니다. –

+0

예'config/initializers' 폴더 ..... 코드 아래에있는 파일들은 어플리케이션이 초기화되거나 시작될 때 실행됩니다. –

답변

0

fixtures 또는 factory_girl 사용할 수없는 이유가에서) config/initializers/test_data.rb

2에서 파일을 생성?

은기구를 사용하려면 crm_donation_email_types.yml 이름 spec/fixtures 또는 test/fixturesyaml 파일을 배치 할 및 내용이 특정 모델에 대한 단위 테스트를 실행할 때

to: 
    id: 1 
    email_type: to 
    updated_at: <%= DateTime.parse '2013-08-28 05:19:08' %> 
    created_at: <%= DateTime.parse '2013-08-28 05:19:08' %> 

cc: 
    id: 2 
    email_type: cc 
    updated_at: <%= DateTime.parse '2013-08-28 05:19:15' %> 
    created_at: <%= Datetime.parse '2013-08-28 05:19:15' %> 

bcc: 
    id: 3 
    email_type: bcc 
    updated_at: <%= DateTime.parse '2013-08-28 05:19:26' 
    created_at: <%= DateTime.parse '2013-08-28 05:19:26' 

from: 
    id: 4 
    email_type: from 
    updated_at: <%= '2013-08-28 05:19:35' %> 
    created_at: <%= '2013-08-28 05:19:35' %> 

레일이 파일에 따라 레코드를 삽입합니다

것 . 다른 테스트에서 이러한 조명기가 필요하면 fixtures 클래스 메소드를 사용하십시오. 모든 세부 사항은 2.3 The Low-Down on Fixtures을 읽으십시오.

factory_girl로 이동하려면 GETTING_STARTED 가이드를 읽어보십시오.

0

1) 해당 파일

conn = ActiveRecord::Base.establish_connection(:adapter => "mysql", :host => "localhost", :username => "myuser", :password => "mypass", :database => "test_database") 

    conn.execute("INSERT INTO 'crm_donation_email_types' ('id', 'emailtype', 'created_at', 'updated_at') VALUES (1, 'to', '2013-08-28 05:19:08', '2013-08-28 05:19:08'), (2, 'cc', '2013-08-28 05:19:15', '2013-08-28 05:19:15'), (3, 'bcc', '2013-08-28 05:19:26', '2013-08-28 05:19:26'), (4, 'from', '2013-08-28 05:19:35', '2013-08-28 05:19:35');")