{"id":21285504,"url":"https://github.com/takeyuweb/temporary_model","last_synced_at":"2026-05-14T20:05:57.228Z","repository":{"id":59157474,"uuid":"124478149","full_name":"takeyuweb/temporary_model","owner":"takeyuweb","description":"You can define a temporary model class and use it in ActiveSupport::TestCase.","archived":false,"fork":false,"pushed_at":"2024-03-25T06:59:44.000Z","size":46,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-05T16:36:16.942Z","etag":null,"topics":["activerecord","minitest","rails","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takeyuweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-09T02:46:29.000Z","updated_at":"2024-03-25T06:57:19.000Z","dependencies_parsed_at":"2024-11-15T05:04:02.239Z","dependency_job_id":"08d64353-40e4-4522-9325-5057c2b0c062","html_url":"https://github.com/takeyuweb/temporary_model","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"ef2e482130b1e9b26324fac539d8c5c666a77f15"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/takeyuweb/temporary_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Ftemporary_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Ftemporary_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Ftemporary_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Ftemporary_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takeyuweb","download_url":"https://codeload.github.com/takeyuweb/temporary_model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Ftemporary_model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33041248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","minitest","rails","rubygem"],"created_at":"2024-11-21T11:20:50.641Z","updated_at":"2026-05-14T20:05:57.211Z","avatar_url":"https://github.com/takeyuweb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TemporaryModel\nYou can define a temporary class and use it in ActiveSupport::TestCase.\n\n## Usage\n\n### Minitest\n\n```ruby\nclass YourTest \u003c ActiveSupport::TestCase\n  include TemporaryModel::TestHelper # 1 of 2\n\n  # 2 of 2\n  temporary_model 'Post' do\n    define_table do |t|\n      t.string :title, default: '', null: false\n    end\n\n    has_many :taggings, as: :taggable, dependent: :destroy\n    has_many :tags, through: :taggings, source: :tag\n\n    validates :title, presence: true\n\n    # You can use custom validators\n    validates_with YourCustomValidator\n\n    # You can use Active Storage\n    has_one_attached :doc\n    has_many_attached :docs \n\n    def tag_names\n      tags.pluck(:name)\n    end\n  end\n\n  test 'truthy' do\n    post = Post.create!(title: 'Hello')\n    assert 'Hello', post.title\n  end\nend\n```\n\nPlease check test/*test.rb\n\n### RSpec\n\n```ruby\nrequire 'rails_helper'\n\nRSpec.describe 'TemporaryModelSpec' do\n  include TemporaryModel::TestHelper\n\n  temporary_model 'Tag' do\n    define_table do |t|\n      t.string :name, default: '', null: false\n    end\n\n    has_many :taggings, dependent: :destroy\n    has_many :posts, through: :taggings, source: :taggable, source_type: 'Post'\n\n    validates :name, presence: true\n  end\n\n  temporary_model 'Post' do\n    define_table do |t|\n      t.string :title, default: '', null: false\n    end\n\n    has_many :taggings, as: :taggable, dependent: :destroy\n    has_many :tags, through: :taggings, source: :tag\n\n    validates :title, presence: true\n\n    def tag_names\n      tags.pluck(:name)\n    end\n  end\n\n  temporary_model 'Tagging' do\n    define_table do |t|\n      t.references :tag, foreign_key: true\n      t.references :taggable, polymorphic: true\n    end\n\n    belongs_to :tag\n    belongs_to :taggable, polymorphic: true\n  end\n\n  let(:ruby) { Post.create!(title: 'Ruby') }\n  let(:rust) { Post.create!(title: 'Rust') }\n  \n  before do\n    ruby.taggings.create!(tag: Tag.create(name: 'Programming_Language'))\n    ruby.taggings.create!(tag: Tag.create(name: 'Dynamic_Typing'))\n\n    rust.taggings.create!(tag: Tag.create(name: 'Programming_Language'))\n    rust.taggings.create!(tag: Tag.create(name: 'Static_Typing'))\n  end\n  \n  example 'You can define and use temporary classes' do\n    expect(ruby.title).to eq 'Ruby'\n  end\n  \n  example 'Of course you can also use relation' do\n    expect(ruby.tag_names).to contain_exactly('Programming_Language', 'Dynamic_Typing')\n    expect(Tag.find_by(name: 'Static_Typing').posts).to match_array([rust])\n  end\nend\n```\n\n\nPlease check spec/*_spec.rb\n\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'temporary_model'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install temporary_model\n```\n\n## Contributing\nContribution directions go here.\n\ntesting\n\n```\nbundle exec rake\nbundle exec rspec\n```\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Ftemporary_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakeyuweb%2Ftemporary_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Ftemporary_model/lists"}