Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Users
- User.create!(name: "Example User",
- email: "example@railstutorial.org",
- password: "foobar",
- password_confirmation: "foobar",
- admin: true,
- activated: true,
- activated_at: Time.zone.now)
- 99.times do |n|
- name = Faker::Name.name
- email = "example-#{n+1}@railstutorial.org"
- password = "password"
- User.create!(name: name,
- email: email,
- password: password,
- password_confirmation: password,
- activated: true,
- activated_at: Time.zone.now)
- end
- # Microposts
- users = User.order(:created_at).take(6)
- image_path = File.join(Rails.root, "test/fixtures/images/sample.jpg")
- 50.times do
- content = Faker::Lorem.sentence(5)
- users.each { |user|
- # 画像と一緒にマイクロポストの初期データを作成する
- user.microposts.create!(content: content, picture: File.new(image_path))
- }
- end
- # Following relationships
- users = User.all
- user = users.first
- following = users[2..50]
- followers = users[3..40]
- following.each { |followed| user.follow(followed) }
- followers.each { |follower| follower.follow(user) }
- schema.rb
- create_table "hoges"
- t.binary "photo", limit: 65535
- end
- path = Rails.root.join("画像が置いてあるパス")
- photo = File.open(path, "rb").read
- require 'active_record/fixtures'
- module FileFixtureExtension
- def file(file_name)
- File::open(Rails.root.join('test/fixtures/', file_name), 'rb') do |f|
- "!!binary "#{Base64.strict_encode64(f.read)}""
- end
- end
- end
- ActiveRecord::Fixture.extend FileFixtureExtension
- one:
- user: :one
- file: <%= ActiveRecord::Fixture::file 'files_to_upload/test.png' %>
- sudo apt search ag|grep "silver"
- silversearcher-ag-el/xenial,xenial 0.46-2 all
- sudo apt install silversearcher-ag
- bundle exec rails test
- .../config/initializers/file_fixtures_extension.rb:11:in `<top
- (required)>': uninitialized constant Fixture (NameError)
- from /home/d/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:655:in `block in load_config_initializer'
- cd /home/d/.rvm/gems/ruby-2.4.0/gems
- ag 'class Fixture '
- activerecord-5.1.4/lib/active_record/fixtures.rb
- 11: class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
- 412: class FixtureSet
- 804: class Fixture #:nodoc:
- 807: class FixtureError < StandardError #:nodoc:
- test "should update user" do
- #file = Rack::Test::UploadedFile.new(Rails.root.join("test/fixtures/files_to_upload/test.png"))
- file = fixture_file_upload('/files_to_upload/test.png','image/png')
- patch user_url(@user),
- params: {
- user: {
- name:'new name',
- file: file,
- }
- }
- assert_redirected_to user_url(@user)
- end
Add Comment
Please, Sign In to add comment