diff --git a/app/Ejaculation.php b/app/Ejaculation.php index 0f3522c..a270f40 100644 --- a/app/Ejaculation.php +++ b/app/Ejaculation.php @@ -12,6 +12,9 @@ class Ejaculation extends Model { use HasEagerLimit; + const SOURCE_WEB = 'web'; + const SOURCE_CSV = 'csv'; + protected $fillable = [ 'user_id', 'ejaculated_date', 'note', 'geo_latitude', 'geo_longitude', 'link', diff --git a/app/Io/CheckinCsvImporter.php b/app/Io/CheckinCsvImporter.php index 30d13d4..1239667 100644 --- a/app/Io/CheckinCsvImporter.php +++ b/app/Io/CheckinCsvImporter.php @@ -69,6 +69,7 @@ class CheckinCsvImporter $ejaculation->ejaculated_date = Carbon::createFromFormat('!Y/m/d H:i+', $record['日時']); $ejaculation->note = str_replace(["\r\n", "\r"], "\n", $record['ノート'] ?? ''); $ejaculation->link = $record['オカズリンク'] ?? ''; + $ejaculation->source = Ejaculation::SOURCE_CSV; try { $tags = $this->parseTags($line, $record); diff --git a/database/migrations/2020_02_17_085327_add_source_to_ejaculations.php b/database/migrations/2020_02_17_085327_add_source_to_ejaculations.php new file mode 100644 index 0000000..965e398 --- /dev/null +++ b/database/migrations/2020_02_17_085327_add_source_to_ejaculations.php @@ -0,0 +1,38 @@ +string('name'); + $table->primary('name'); + }); + Schema::table('ejaculations', function (Blueprint $table) { + $table->string('source')->nullable(); + $table->foreign('source')->references('name')->on('ejaculation_sources'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ejaculations', function (Blueprint $table) { + $table->dropColumn('source'); + }); + Schema::drop('ejaculation_sources'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db6..3f0fc32 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + $this->call(EjaculationSourcesSeeder::class); } } diff --git a/database/seeds/EjaculationSourcesSeeder.php b/database/seeds/EjaculationSourcesSeeder.php new file mode 100644 index 0000000..a762a08 --- /dev/null +++ b/database/seeds/EjaculationSourcesSeeder.php @@ -0,0 +1,19 @@ +insert(['name' => $source]); + } + } +} diff --git a/tests/Unit/Io/CheckinCsvImporterTest.php b/tests/Unit/Io/CheckinCsvImporterTest.php index f3ecfb3..a486760 100644 --- a/tests/Unit/Io/CheckinCsvImporterTest.php +++ b/tests/Unit/Io/CheckinCsvImporterTest.php @@ -2,6 +2,7 @@ namespace Tests\Unit\Io; +use App\Ejaculation; use App\Exceptions\CsvImportException; use App\Io\CheckinCsvImporter; use App\User; @@ -13,6 +14,12 @@ class CheckinCsvImporterTest extends TestCase { use RefreshDatabase; + protected function setUp() + { + parent::setUp(); + $this->seed(); + } + public function testIncompatibleCharsetEUCJP() { $user = factory(User::class)->create(); @@ -231,4 +238,16 @@ class CheckinCsvImporterTest extends TestCase $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/tag-multiline.utf8.csv'); $importer->execute(); } + + public function testSourceIsCsv() + { + $user = factory(User::class)->create(); + + $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date.utf8.csv'); + $importer->execute(); + $ejaculation = $user->ejaculations()->first(); + + $this->assertSame(1, $user->ejaculations()->count()); + $this->assertEquals(Ejaculation::SOURCE_CSV, $ejaculation->source); + } }