diff --git a/app/models/movie.rb b/app/models/movie.rb index 0c8266d..a319998 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -15,9 +15,7 @@ def initialize(msg = "That Relationship Type doesn't exist") def add_many(type, data) if type.in? ['Genre', 'Crew'] - type_plural = type.downcase.pluralize - - self.send("#{type_plural}=", data.map do |g| + self.send("#{type.downcase.pluralize}=", data.map do |g| type.classify.constantize.where(name: g).first_or_create! end) else diff --git a/app/models/role.rb b/app/models/role.rb new file mode 100644 index 0000000..d152cd6 --- /dev/null +++ b/app/models/role.rb @@ -0,0 +1,4 @@ +class Role < ActiveRecord::Base + belongs_to :movie + belongs_to :crew +end diff --git a/db/migrate/20150501101641_add_fields_to_movies.rb b/db/migrate/20150501101641_add_fields_to_movies.rb new file mode 100644 index 0000000..151029f --- /dev/null +++ b/db/migrate/20150501101641_add_fields_to_movies.rb @@ -0,0 +1,10 @@ +class AddFieldsToMovies < ActiveRecord::Migration + def change + add_column :movies, :country, :string + add_column :movies, :year, :integer + add_column :movies, :review, :float + add_column :movies, :rating, :string + add_column :movies, :runtime, :integer + add_column :movies, :language, :string + end +end diff --git a/db/migrate/20150501102555_create_roles.rb b/db/migrate/20150501102555_create_roles.rb new file mode 100644 index 0000000..600243a --- /dev/null +++ b/db/migrate/20150501102555_create_roles.rb @@ -0,0 +1,13 @@ +class CreateRoles < ActiveRecord::Migration + def change + create_table :roles do |t| + t.references :movie, index: true + t.references :crew, index: true + t.string :job + + t.timestamps null: false + end + add_foreign_key :roles, :movies + add_foreign_key :roles, :crews + end +end diff --git a/db/migrate/20150501102639_drop_crews_movies.rb b/db/migrate/20150501102639_drop_crews_movies.rb new file mode 100644 index 0000000..1f05452 --- /dev/null +++ b/db/migrate/20150501102639_drop_crews_movies.rb @@ -0,0 +1,5 @@ +class DropCrewsMovies < ActiveRecord::Migration + def change + drop_table :crews_movies + end +end diff --git a/db/migrate/20150501104039_add_release_date_to_movies.rb b/db/migrate/20150501104039_add_release_date_to_movies.rb new file mode 100644 index 0000000..3039c5c --- /dev/null +++ b/db/migrate/20150501104039_add_release_date_to_movies.rb @@ -0,0 +1,5 @@ +class AddReleaseDateToMovies < ActiveRecord::Migration + def change + add_column :movies, :release_date, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 8c1e5a8..b37afdf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150501072034) do +ActiveRecord::Schema.define(version: 20150501104039) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -23,14 +23,6 @@ t.datetime "updated_at", null: false end - create_table "crews_movies", id: false, force: :cascade do |t| - t.integer "crew_id" - t.integer "movie_id" - end - - add_index "crews_movies", ["crew_id"], name: "index_crews_movies_on_crew_id", using: :btree - add_index "crews_movies", ["movie_id"], name: "index_crews_movies_on_movie_id", using: :btree - create_table "genres", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -48,8 +40,28 @@ create_table "movies", force: :cascade do |t| t.string "name" t.text "synopsis" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "country" + t.integer "year" + t.float "review" + t.string "rating" + t.integer "runtime" + t.string "language" + t.date "release_date" + end + + create_table "roles", force: :cascade do |t| + t.integer "movie_id" + t.integer "crew_id" + t.string "job" t.datetime "created_at", null: false t.datetime "updated_at", null: false end + add_index "roles", ["crew_id"], name: "index_roles_on_crew_id", using: :btree + add_index "roles", ["movie_id"], name: "index_roles_on_movie_id", using: :btree + + add_foreign_key "roles", "crews" + add_foreign_key "roles", "movies" end diff --git a/lib/tasks/omdb.thor b/lib/tasks/omdb.thor index c93f579..55f3524 100644 --- a/lib/tasks/omdb.thor +++ b/lib/tasks/omdb.thor @@ -1,10 +1,15 @@ +require 'thor' require File.expand_path('config/environment.rb') class Omdb < Thor def import movies = Sequel.connect('postgres://zacksiri@localhost:5432/omdb')[:movies] movies.each do |movie| - + Movie.create do |m| + m.name = movie[:Title] + m.synopsis = movie[:FullPlot] unless movie[:FullPlot] == 'N/A' + m.year = + end end end end \ No newline at end of file diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml new file mode 100644 index 0000000..e69f849 --- /dev/null +++ b/test/fixtures/roles.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + movie_id: + crew_id: + job: MyString + +two: + movie_id: + crew_id: + job: MyString diff --git a/test/models/role_test.rb b/test/models/role_test.rb new file mode 100644 index 0000000..11c53a8 --- /dev/null +++ b/test/models/role_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RoleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end